1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Actions; |
4
|
|
|
|
5
|
|
|
use Nwidart\Modules\Facades\Module; |
6
|
|
|
use Illuminate\Support\Facades\Gate; |
7
|
|
|
|
8
|
|
|
use App\Traits\AllowTrait; |
9
|
|
|
|
10
|
|
|
class BuildNavbar |
11
|
|
|
{ |
12
|
|
|
use AllowTrait; |
13
|
|
|
|
14
|
|
|
protected $user; |
15
|
|
|
|
16
|
|
|
public function build($user) |
17
|
|
|
{ |
18
|
|
|
$this->user = $user; |
19
|
|
|
|
20
|
|
|
$admin = $this->getAdminNavbar(); |
21
|
|
|
$navBar = $this->getPrimaryNavbar(); |
22
|
|
|
$modules = $this->getModules(); |
23
|
|
|
array_splice($navBar, 1, 0, $admin); // Move the Admin link just under the Dashboard link |
24
|
|
|
|
25
|
|
|
return array_merge($navBar, $modules); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/* |
29
|
|
|
* Main navigation menu that is always included |
30
|
|
|
*/ |
31
|
|
|
protected function getPrimaryNavbar() |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
[ |
35
|
|
|
'name' => 'Dashboard', |
36
|
|
|
'route' => route('dashboard'), |
37
|
|
|
'icon' => 'fas fa-tachometer-alt', |
38
|
|
|
], |
39
|
|
|
[ |
40
|
|
|
'name' => 'Customers', |
41
|
|
|
'route' => route('customers.index'), |
42
|
|
|
'icon' => 'fas fa-user-tie', |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'name' => 'Tech Tips', |
46
|
|
|
'route' => route('tech-tips.index'), |
47
|
|
|
'icon' => 'fas fa-tools', |
48
|
|
|
], |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/* |
53
|
|
|
* If the user has any admin abilities, show the admin link |
54
|
|
|
*/ |
55
|
|
|
protected function getAdminNavbar() |
56
|
|
|
{ |
57
|
|
|
if(Gate::allows('admin-link', $this->user)) |
58
|
|
|
{ |
59
|
|
|
return [[ |
60
|
|
|
'name' => 'Administration', |
61
|
|
|
'route' => route('admin.index'), |
62
|
|
|
'icon' => 'fas fa-user-shield', |
63
|
|
|
]]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return []; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* |
70
|
|
|
* If any add-on modules have been installed, add those to the navigation bar |
71
|
|
|
*/ |
72
|
|
|
protected function getModules() |
73
|
|
|
{ |
74
|
|
|
$nav = []; |
75
|
|
|
$modules = Module::allEnabled(); |
76
|
|
|
|
77
|
|
|
foreach($modules as $module) |
78
|
|
|
{ |
79
|
|
|
$name = $module->getLowerName(); |
80
|
|
|
$navData = config($name.'.navbar'); |
81
|
|
|
|
82
|
|
|
if($navData) |
83
|
|
|
{ |
84
|
|
|
foreach($navData as $n) |
85
|
|
|
{ |
86
|
|
|
if(!isset($n['perm_name']) || $this->checkPermission($this->user, $n['perm_name'])) |
87
|
|
|
{ |
88
|
|
|
$nav[] = [ |
89
|
|
|
'name' => $n['name'], |
90
|
|
|
'route' => route($n['route']), |
91
|
|
|
'icon' => $n['icon'], |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $nav; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|