|
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
|
|
|
|
|
19
|
23 |
|
$modules = $this->getModules(); |
|
20
|
|
|
|
|
21
|
23 |
|
return array_merge($navBar, $admin, $modules); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/* |
|
25
|
|
|
* Main navigation menu that is always included |
|
26
|
|
|
*/ |
|
27
|
23 |
|
protected function getPrimaryNavbar() |
|
28
|
|
|
{ |
|
29
|
|
|
return [ |
|
30
|
|
|
[ |
|
31
|
23 |
|
'name' => 'Dashboard', |
|
32
|
23 |
|
'route' => route('dashboard'), |
|
33
|
23 |
|
'icon' => 'fas fa-tachometer-alt', |
|
34
|
|
|
], |
|
35
|
|
|
[ |
|
36
|
23 |
|
'name' => 'Customers', |
|
37
|
23 |
|
'route' => route('customers.index'), |
|
38
|
23 |
|
'icon' => 'fas fa-user-tie', |
|
39
|
|
|
], |
|
40
|
|
|
[ |
|
41
|
|
|
'name' => 'Tech Tips', |
|
42
|
|
|
'route' => '#', |
|
43
|
|
|
'icon' => 'fas fa-tools', |
|
44
|
|
|
], |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/* |
|
49
|
|
|
* If the user has any admin abilities, show the admin link |
|
50
|
|
|
*/ |
|
51
|
23 |
|
protected function getAdminNavbar() |
|
52
|
|
|
{ |
|
53
|
23 |
|
if(Gate::allows('admin-link', $this->user)) |
|
54
|
|
|
{ |
|
55
|
|
|
return [[ |
|
56
|
17 |
|
'name' => 'Administration', |
|
57
|
17 |
|
'route' => route('admin.index'), |
|
58
|
17 |
|
'icon' => 'fas fa-user-shield', |
|
59
|
|
|
]]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
6 |
|
return []; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Get landing routes for all active modules |
|
66
|
23 |
|
protected function getModules() |
|
67
|
|
|
{ |
|
68
|
23 |
|
$nav = []; |
|
69
|
23 |
|
$modules = Module::allEnabled(); |
|
70
|
|
|
|
|
71
|
23 |
|
foreach($modules as $module) |
|
72
|
|
|
{ |
|
73
|
|
|
$name = $module->getLowerName(); |
|
74
|
|
|
$navData = config($name.'.navbar'); |
|
75
|
|
|
|
|
76
|
|
|
if($navData['enable']) |
|
77
|
|
|
{ |
|
78
|
|
|
$nav[] = [ |
|
79
|
|
|
'name' => $navData['name'], |
|
80
|
|
|
'route' => route($navData['route']), |
|
81
|
|
|
'icon' => $navData['icon'], |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
23 |
|
return $nav; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|