1
|
|
|
<?php namespace Modules\Blog\Sidebar; |
2
|
|
|
|
3
|
|
|
use Maatwebsite\Sidebar\Group; |
4
|
|
|
use Maatwebsite\Sidebar\Item; |
5
|
|
|
use Maatwebsite\Sidebar\Menu; |
6
|
|
|
use Modules\Core\Contracts\Authentication; |
7
|
|
|
|
8
|
|
|
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var Authentication |
12
|
|
|
*/ |
13
|
|
|
protected $auth; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param Authentication $auth |
17
|
|
|
* |
18
|
|
|
* @internal param Guard $guard |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Authentication $auth) |
21
|
|
|
{ |
22
|
|
|
$this->auth = $auth; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Menu $menu |
27
|
|
|
* |
28
|
|
|
* @return Menu |
29
|
|
|
*/ |
30
|
|
|
public function extendWith(Menu $menu) |
31
|
|
|
{ |
32
|
|
|
$menu->group(trans('core::sidebar.content'), function (Group $group) { |
33
|
|
|
$group->item(trans('blog::blog.title'), function (Item $item) { |
34
|
|
|
|
35
|
|
|
$item->icon('fa fa-copy'); |
36
|
|
|
$item->weight(0); |
37
|
|
|
|
38
|
|
View Code Duplication |
$item->item(trans('blog::post.title.post'), function (Item $item) { |
|
|
|
|
39
|
|
|
$item->icon('fa fa-copy'); |
40
|
|
|
$item->weight(0); |
41
|
|
|
$item->append('admin.blog.post.create'); |
42
|
|
|
$item->route('admin.blog.post.index'); |
43
|
|
|
$item->authorize( |
44
|
|
|
$this->auth->hasAccess('blog.posts.index') |
45
|
|
|
); |
46
|
|
|
}); |
47
|
|
View Code Duplication |
$item->item(trans('blog::tag.title.tag'), function (Item $item) { |
|
|
|
|
48
|
|
|
$item->icon('fa fa-tags'); |
49
|
|
|
$item->weight(0); |
50
|
|
|
$item->append('admin.blog.tag.create'); |
51
|
|
|
$item->route('admin.blog.tag.index'); |
52
|
|
|
$item->authorize( |
53
|
|
|
$this->auth->hasAccess('blog.tags.index') |
54
|
|
|
); |
55
|
|
|
}); |
56
|
|
View Code Duplication |
$item->item(trans('blog::category.title.category'), function (Item $item) { |
|
|
|
|
57
|
|
|
$item->icon('fa fa-file-text'); |
58
|
|
|
$item->weight(1); |
59
|
|
|
$item->route('admin.blog.category.index'); |
60
|
|
|
$item->append('admin.blog.category.create'); |
61
|
|
|
$item->authorize( |
62
|
|
|
$this->auth->hasAccess('blog.categories.index') |
63
|
|
|
); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
}); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
return $menu; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.