PostCategoryController::edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\PostCategoryStoreRequest;
6
use App\Services\PostCategoryService;
7
8
class PostCategoryController extends Controller
9
{
10
    private $postCategoryService;
11
12
    public function __construct(
13
        PostCategoryService $postCategoryService
14
    )
15
    {
16
        $this->postCategoryService = $postCategoryService;
17
    }
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Contracts\View\View
22
     */
23
    public function index()
24
    {
25
        $postCategories = $this->postCategoryService->getPostCategories();
26
27
        return view('postCategories.index', [
28
            'postCategories' => $postCategories,
29
        ]);
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Contracts\View\View
36
     */
37
    public function create()
38
    {
39
        return view('postCategories.create');
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param \App\Http\Requests\PostCategoryStoreRequest $request
46
     *
47
     * @return \Illuminate\Http\RedirectResponse
48
     */
49
    public function store(PostCategoryStoreRequest $request)
50
    {
51
        $this->postCategoryService->createPostCategory($request);
52
53
        return redirect()->route('postCategories.index')
54
            ->with('success', 'Post category created successfully');
55
    }
56
57
    /**
58
     * Show the form for editing the specified resource.
59
     *
60
     * @param int $postCategoryId
61
     *
62
     * @return \Illuminate\Contracts\View\View
63
     */
64
    public function edit(int $postCategoryId)
65
    {
66
        $postCategory = $this->postCategoryService->getById($postCategoryId);
67
68
        return view('postCategories.edit', [
69
            'postCategory' => $postCategory,
70
        ]);
71
    }
72
73
    /**
74
     * Update the specified resource in storage.
75
     *
76
     * @param \App\Http\Requests\PostCategoryStoreRequest $request
77
     * @param int $postCategoryId
78
     *
79
     * @return \Illuminate\Http\RedirectResponse
80
     */
81
    public function update(PostCategoryStoreRequest $request, int $postCategoryId)
82
    {
83
        $this->postCategoryService->updatePostCategory($request, $postCategoryId);
84
85
        return redirect()->route('postCategories.index')
86
            ->with('success', 'Post category updated successfully');
87
    }
88
89
    /**
90
     * Remove the specified resource from storage.
91
     *
92
     * @param int $postCategoryId
93
     *
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function destroy(int $postCategoryId)
97
    {
98
        $this->postCategoryService->deletePostCategory($postCategoryId);
99
100
        return redirect()->route('postCategories.index')
101
            ->with('success', 'Post category deleted successfully');
102
    }
103
}
104