Completed
Push — master ( 2ccb51...4b9a6b )
by ARCANEDEV
02:56
created

CategoriesController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Blog\Http\Controllers\Foundation;
2
3
use Arcanesoft\Blog\Bases\FoundationController;
4
use Arcanesoft\Blog\Http\Requests\Backend\Categories\CreateCategoryRequest;
5
use Arcanesoft\Blog\Http\Requests\Backend\Categories\UpdateCategoryRequest;
6
use Arcanesoft\Blog\Models\Category;
7
use Illuminate\Support\Facades\Log;
8
9
/**
10
 * Class     CategoriesController
11
 *
12
 * @package  Arcanesoft\Blog\Http\Controllers\Foundation
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class CategoriesController extends FoundationController
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Properties
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * The category model.
23
     *
24
     * @var \Arcanesoft\Blog\Models\Category
25
     */
26
    private $category;
27
28
    /* ------------------------------------------------------------------------------------------------
29
     |  Constructor
30
     | ------------------------------------------------------------------------------------------------
31
     */
32
    /**
33
     * Instantiate the controller.
34
     *
35
     * @param  \Arcanesoft\Blog\Models\Category  $category
36
     */
37
    public function __construct(Category $category)
38
    {
39
        parent::__construct();
40
41
        $this->category = $category;
42
43
        $this->setCurrentPage('blog-categories');
44
        $this->addBreadcrumbRoute('Categories', 'blog::foundation.categories.index');
45
    }
46
47
    /* ------------------------------------------------------------------------------------------------
48
     |  Main Functions
49
     | ------------------------------------------------------------------------------------------------
50
     */
51
    public function index($trashed = false)
52
    {
53
        $this->authorize('blog.categories.list');
54
55
        $categories = $this->category->with(['posts']);
56
        $categories = $trashed
57
            ? $categories->onlyTrashed()->paginate(30)
58
            : $categories->paginate(30);
59
60
        $title = 'Blog - Categories';
61
        $this->setTitle($title);
62
        $this->addBreadcrumb('List all categories');
63
64
        return $this->view('foundation.categories.list', compact('categories', 'trashed'));
65
    }
66
67
    public function trash()
68
    {
69
        return $this->index(true);
70
    }
71
72
    public function create()
73
    {
74
        $this->authorize('blog.categories.create');
75
76
        $title = 'Blog - Categories';
77
        $this->setTitle($title);
78
        $this->addBreadcrumb('Create category');
79
80
        return $this->view('foundation.categories.create');
81
    }
82
83
    public function store(CreateCategoryRequest $request, Category $category)
84
    {
85
        $this->authorize('blog.categories.create');
86
87
        $category->fill($request->only(['name']));
88
        $category->save();
89
90
        $message = "The category {$category->name} was created successfully !";
91
        Log::info($message, $category->toArray());
92
        $this->notifySuccess($message, 'Category created !');
93
94
        return redirect()->route('blog::foundation.categories.index');
95
    }
96
97
    public function show(Category $category)
98
    {
99
        $this->authorize('blog.categories.show');
100
101
        $category->load(['posts']);
102
103
        $title = 'Blog - Categories';
104
        $this->setTitle($title);
105
        $this->addBreadcrumb('Category - ' . $category->name);
106
107
        return $this->view('foundation.categories.show', compact('category'));
108
    }
109
110
    public function edit(Category $category)
111
    {
112
        $this->authorize('blog.categories.update');
113
114
        $title = 'Blog - Categories';
115
        $this->setTitle($title);
116
        $this->addBreadcrumb('Update category');
117
118
        return $this->view('foundation.categories.edit', compact('category'));
119
    }
120
121
    public function update(UpdateCategoryRequest $request, Category $category)
122
    {
123
        $this->authorize('blog.categories.update');
124
125
        $category->update($request->only(['name']));
126
127
        $message = "The category {$category->name} was updated successfully !";
128
        Log::info($message, $category->toArray());
129
        $this->notifySuccess($message, 'Category updated !');
130
131
        return redirect()->route('blog::foundation.categories.show', [$category->id]);
132
    }
133
134
    public function restore(Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $category is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
135
    {
136
        $this->authorize('blog.categories.update');
137
    }
138
139
    public function delete(Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $category is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
140
    {
141
        $this->authorize('blog.categories.delete');
142
    }
143
}
144