1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Controllers\Foundation; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Bases\FoundationController; |
4
|
|
|
use Arcanesoft\Auth\Http\Requests\Backend\Roles\CreateRoleRequest; |
5
|
|
|
use Arcanesoft\Auth\Http\Requests\Backend\Roles\UpdateRoleRequest; |
6
|
|
|
use Arcanesoft\Auth\Models\Role; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class RolesController |
11
|
|
|
* |
12
|
|
|
* @package Arcanesoft\Auth\Http\Controllers\Foundation |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class RolesController extends FoundationController |
16
|
|
|
{ |
17
|
|
|
/* ------------------------------------------------------------------------------------------------ |
18
|
|
|
| Constructor |
19
|
|
|
| ------------------------------------------------------------------------------------------------ |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* Instantiate the controller. |
23
|
|
|
*/ |
24
|
|
|
public function __construct() |
25
|
|
|
{ |
26
|
|
|
parent::__construct(); |
27
|
|
|
|
28
|
|
|
$this->setCurrentPage('auth-roles'); |
29
|
|
|
$this->addBreadcrumbRoute('Roles', 'auth::foundation.roles.index'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/* ------------------------------------------------------------------------------------------------ |
33
|
|
|
| Main Functions |
34
|
|
|
| ------------------------------------------------------------------------------------------------ |
35
|
|
|
*/ |
36
|
|
|
public function index() |
37
|
|
|
{ |
38
|
|
|
$roles = Role::with('users', 'permissions')->paginate(30); |
39
|
|
|
|
40
|
|
|
$title = 'List of roles'; |
41
|
|
|
$this->setTitle($title); |
42
|
|
|
$this->addBreadcrumb($title); |
43
|
|
|
|
44
|
|
|
return $this->view('foundation.roles.list', compact('roles')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function create() |
48
|
|
|
{ |
49
|
|
|
$title = 'Create a role'; |
50
|
|
|
$this->setTitle($title); |
51
|
|
|
$this->addBreadcrumb($title); |
52
|
|
|
|
53
|
|
|
return $this->view('foundation.roles.create'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function store(CreateRoleRequest $request, Role $role) |
57
|
|
|
{ |
58
|
|
|
$role->fill($request->only('name', 'slug', 'description')); |
59
|
|
|
$role->save(); |
60
|
|
|
$role->permissions()->attach($request->get('permissions')); |
61
|
|
|
|
62
|
|
|
$message = 'The new role was successfully created !'; |
63
|
|
|
|
64
|
|
|
Log::info($message, $role->toArray()); |
65
|
|
|
|
66
|
|
|
return redirect() |
67
|
|
|
->route('auth::foundation.roles.index') |
68
|
|
|
->with('success', $message); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function show(Role $role) |
72
|
|
|
{ |
73
|
|
|
$role->load(['users', 'permissions', 'permissions.group']); |
74
|
|
|
|
75
|
|
|
$title = 'Role details'; |
76
|
|
|
$this->setTitle($title); |
77
|
|
|
$this->addBreadcrumb($title); |
78
|
|
|
|
79
|
|
|
return $this->view('foundation.roles.show', compact('role')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function edit(Role $role) |
83
|
|
|
{ |
84
|
|
|
$role->load(['users', 'permissions']); |
85
|
|
|
|
86
|
|
|
$title = 'Edit Role'; |
87
|
|
|
$this->setTitle($title); |
88
|
|
|
$this->addBreadcrumb($title); |
89
|
|
|
|
90
|
|
|
return $this->view('foundation.roles.edit', compact('role')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function update(UpdateRoleRequest $request, Role $role) |
94
|
|
|
{ |
95
|
|
|
$role->fill($request->only('name', 'slug', 'description')); |
96
|
|
|
$role->save(); |
97
|
|
|
$role->permissions()->sync($request->get('permissions')); |
98
|
|
|
|
99
|
|
|
$message = 'The role was successfully updated !'; |
100
|
|
|
|
101
|
|
|
Log::info($message, $role->toArray()); |
102
|
|
|
|
103
|
|
|
return redirect() |
104
|
|
|
->route('auth::foundation.roles.show', [$role->hashed_id]) |
|
|
|
|
105
|
|
|
->with('success', $message); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function delete(Role $role) |
109
|
|
|
{ |
110
|
|
|
self::onlyAjax(); |
111
|
|
|
|
112
|
|
|
try { |
113
|
|
|
$role->delete(); |
114
|
|
|
|
115
|
|
|
$message = "The role {$role->name} has been successfully deleted."; |
116
|
|
|
Log::info($message, $role->toArray()); |
117
|
|
|
|
118
|
|
|
$ajax = [ |
119
|
|
|
'status' => 'success', |
120
|
|
|
'message' => $message, |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
catch(\Exception $e) { |
124
|
|
|
$ajax = [ |
125
|
|
|
'status' => 'error', |
126
|
|
|
'message' => $e->getMessage(), |
127
|
|
|
]; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return response()->json($ajax); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.