SidebarExtender::extendWith()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4286
cc 1
eloc 12
nc 1
nop 1
1
<?php namespace Modules\Page\Sidebar;
2
3
use Maatwebsite\Sidebar\Badge;
4
use Maatwebsite\Sidebar\Group;
5
use Maatwebsite\Sidebar\Item;
6
use Maatwebsite\Sidebar\Menu;
7
use Modules\Core\Contracts\Authentication;
8
use Modules\Page\Repositories\PageRepository;
9
10
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
11
{
12
    /**
13
     * @var Authentication
14
     */
15
    protected $auth;
16
17
    /**
18
     * @param Authentication $auth
19
     *
20
     * @internal param Guard $guard
21
     */
22
    public function __construct(Authentication $auth)
23
    {
24
        $this->auth = $auth;
25
    }
26
27
    /**
28
     * @param Menu $menu
29
     *
30
     * @return Menu
31
     */
32
    public function extendWith(Menu $menu)
33
    {
34
        $menu->group(trans('core::sidebar.content'), function (Group $group) {
35
            $group->item(trans('page::pages.title.pages'), function (Item $item) {
36
                $item->icon('fa fa-file');
37
                $item->weight(1);
38
                $item->route('admin.page.page.index');
39
                $item->badge(function (Badge $badge, PageRepository $page) {
40
                    $badge->setClass('bg-green');
41
                    $badge->setValue($page->countAll());
42
                });
43
                $item->authorize(
44
                    $this->auth->hasAccess('page.pages.index')
45
                );
46
            });
47
        });
48
49
        return $menu;
50
    }
51
}
52