Menu::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\Widgets;
4
5
use Arrilot\Widgets\AbstractWidget;
6
use Yajra\CMS\Entities\Navigation;
7
8
class Menu extends AbstractWidget
9
{
10
    /**
11
     * The configuration array.
12
     *
13
     * @var array
14
     */
15
    protected $config = [];
16
17
    /**
18
     * Treat this method as a controller action.
19
     * Return view() or other content to display.
20
     *
21
     * @param \Yajra\CMS\Entities\Widget $widget
22
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
23
     */
24
    public function run($widget)
25
    {
26
        $navigation = app('navigation')->findOrFail($widget->param('navigation_id'));
27
28
        if (! $navigation->menus()->count()) {
29
            return ''; // return empty string if navigation does not have menu items
30
        }
31
32
        return view($widget->present()->template(), [
33
            'config' => $this->config,
34
            'widget' => $widget,
35
            'menu'   => 'menu_' . $navigation->type,
36
        ]);
37
    }
38
}
39