1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Controllers\Foundation; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Bases\FoundationController; |
4
|
|
|
use Arcanesoft\Auth\Models\Permission; |
5
|
|
|
use Arcanesoft\Auth\Models\PermissionsGroup; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class PermissionsController |
9
|
|
|
* |
10
|
|
|
* @package Arcanesoft\Auth\Http\Controllers\Foundation |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class PermissionsController extends FoundationController |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Properties |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
/** @var int */ |
20
|
|
|
protected $perPage = 30; |
21
|
|
|
|
22
|
|
|
/* ------------------------------------------------------------------------------------------------ |
23
|
|
|
| Constructor |
24
|
|
|
| ------------------------------------------------------------------------------------------------ |
25
|
|
|
*/ |
26
|
|
|
/** |
27
|
|
|
* Instantiate the controller. |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
|
33
|
|
|
$this->setCurrentPage('auth-permissions'); |
34
|
|
|
$this->addBreadcrumbRoute('Permissions', 'auth::foundation.permissions.index'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/* ------------------------------------------------------------------------------------------------ |
38
|
|
|
| Main Functions |
39
|
|
|
| ------------------------------------------------------------------------------------------------ |
40
|
|
|
*/ |
41
|
|
|
public function index(Permission $permission) |
42
|
|
|
{ |
43
|
|
|
$permissions = $permission->with('group', 'roles') |
44
|
|
|
->orderBy('group_id') |
45
|
|
|
->paginate($this->perPage); |
46
|
|
|
|
47
|
|
|
$title = 'List of permissions'; |
48
|
|
|
$this->setTitle($title); |
49
|
|
|
$this->addBreadcrumb($title); |
50
|
|
|
|
51
|
|
|
return $this->view('foundation.permissions.list', compact('permissions')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function group(Permission $permission, PermissionsGroup $group) |
55
|
|
|
{ |
56
|
|
|
$groupId = $group->id ? $group->id : 0; |
57
|
|
|
|
58
|
|
|
$permissions = $permission->where('group_id', $groupId) |
|
|
|
|
59
|
|
|
->with('group', 'roles') |
60
|
|
|
->paginate($this->perPage); |
61
|
|
|
|
62
|
|
|
$this->addBreadcrumbRoute('List of permissions', 'auth::foundation.permissions.index'); |
63
|
|
|
|
64
|
|
|
$groupName = $groupId == 0 ? 'Custom' : $group->name; |
65
|
|
|
$title = "List of permissions - $groupName"; |
66
|
|
|
$this->setTitle($title); |
67
|
|
|
$this->addBreadcrumb($groupName); |
68
|
|
|
|
69
|
|
|
return $this->view('foundation.permissions.list', compact('permissions')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function show(Permission $permission) |
73
|
|
|
{ |
74
|
|
|
$permission->load(['roles', 'roles.users']); |
75
|
|
|
|
76
|
|
|
$title = 'Permission details'; |
77
|
|
|
$this->setTitle($title); |
78
|
|
|
$this->addBreadcrumb($title); |
79
|
|
|
|
80
|
|
|
return $this->view('foundation.permissions.show', compact('permission')); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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: