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