1
|
|
|
<?php namespace Arcanesoft\Auth\ViewComposers; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Bases\ViewComposer; |
4
|
|
|
use Arcanesoft\Auth\Models\Permission; |
5
|
|
|
use Arcanesoft\Auth\Models\Role; |
6
|
|
|
use Arcanesoft\Auth\Models\User; |
7
|
|
|
use Illuminate\Contracts\View\View; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class DashboardComposer |
11
|
|
|
* |
12
|
|
|
* @package Arcanesoft\Auth\ViewComposers |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class DashboardComposer extends ViewComposer |
16
|
|
|
{ |
17
|
|
|
/* ------------------------------------------------------------------------------------------------ |
18
|
|
|
| Properties |
19
|
|
|
| ------------------------------------------------------------------------------------------------ |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* @var \Arcanesoft\Auth\Models\User |
23
|
|
|
*/ |
24
|
|
|
protected $users; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Arcanesoft\Auth\Models\Role |
28
|
|
|
*/ |
29
|
|
|
protected $roles; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Arcanesoft\Auth\Models\Permission |
33
|
|
|
*/ |
34
|
|
|
protected $permissions; |
35
|
|
|
|
36
|
|
|
/* ------------------------------------------------------------------------------------------------ |
37
|
|
|
| Constructor |
38
|
|
|
| ------------------------------------------------------------------------------------------------ |
39
|
|
|
*/ |
40
|
|
|
/** |
41
|
|
|
* DashboardComposer constructor. |
42
|
|
|
* |
43
|
|
|
* @param User $users |
44
|
|
|
*/ |
45
|
|
|
public function __construct(User $users, Role $roles, Permission $permissions) |
46
|
|
|
{ |
47
|
|
|
$this->users = $users; |
48
|
|
|
$this->roles = $roles; |
49
|
|
|
$this->permissions = $permissions; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/* ------------------------------------------------------------------------------------------------ |
53
|
|
|
| Main Functions |
54
|
|
|
| ------------------------------------------------------------------------------------------------ |
55
|
|
|
*/ |
56
|
|
|
/** |
57
|
|
|
* Compose the view. |
58
|
|
|
* |
59
|
|
|
* @param \Illuminate\Contracts\View\View $view |
60
|
|
|
*/ |
61
|
|
|
public function compose(View $view) |
62
|
|
|
{ |
63
|
|
|
$this->view = $view; |
64
|
|
|
|
65
|
|
|
$this->composeUsersTotal(); |
66
|
|
|
$this->composeRolesTotal(); |
67
|
|
|
$this->composePermissionsTotal(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function composeUsersTotal() |
71
|
|
|
{ |
72
|
|
|
$count = $this->cacheResults('auth-users-count', function() { |
73
|
|
|
return $this->users->count(); |
|
|
|
|
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
$this->view->with('authUsersCount', $count); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function composeRolesTotal() |
80
|
|
|
{ |
81
|
|
|
$count = $this->cacheResults('auth-roles-count', function() { |
82
|
|
|
return $this->roles->count(); |
|
|
|
|
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
$this->view->with('authRolesCount', $count); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function composePermissionsTotal() |
89
|
|
|
{ |
90
|
|
|
$count = $this->cacheResults('auth-permissions-count', function() { |
91
|
|
|
return $this->permissions->count(); |
|
|
|
|
92
|
|
|
}); |
93
|
|
|
|
94
|
|
|
$this->view->with('authPermissionsCount', $count); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: