|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Requests; |
|
7
|
|
|
|
|
8
|
|
|
use App\Roles as Roles; |
|
9
|
|
|
|
|
10
|
|
|
class RolesController extends Controller |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Get the role overview. |
|
14
|
|
|
* |
|
15
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
16
|
|
|
*/ |
|
17
|
|
|
public function index() |
|
18
|
|
|
{ |
|
19
|
|
|
$data['roles'] = Roles::all(); |
|
20
|
|
|
return view('roles.index', $data); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Search for a specific role. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Request $request |
|
28
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
29
|
|
|
*/ |
|
30
|
|
|
public function search(Request $request) |
|
31
|
|
|
{ |
|
32
|
|
|
$term = $request->get('term'); |
|
33
|
|
|
$data['roles'] = Roles::where('name', 'LIKE', "$term")->get(); |
|
34
|
|
|
return view('roles.index', $data); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get a specific role. and display it. |
|
39
|
|
|
* |
|
40
|
|
|
* @param int $id the id off the role in the database. |
|
41
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
42
|
|
|
*/ |
|
43
|
|
|
public function show($id) |
|
44
|
|
|
{ |
|
45
|
|
|
$data['query'] = Roles::find($id); |
|
46
|
|
|
return view('roles.specific', $data); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Store the new role in the database. |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
53
|
|
|
*/ |
|
54
|
|
|
======= |
|
55
|
|
|
public function edit($id) |
|
56
|
|
|
{ |
|
57
|
|
|
return view('roles.edit'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
>>>>>>> master |
|
61
|
|
|
public function store() |
|
62
|
|
|
{ |
|
63
|
|
|
return redirect(302)->back(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Display the form for creating a new role. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
70
|
|
|
*/ |
|
71
|
|
|
public function create() |
|
72
|
|
|
{ |
|
73
|
|
|
return view('roles.create'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the edit form for the selected role. |
|
78
|
|
|
* @param int $id The role id in the database. |
|
79
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
80
|
|
|
*/ |
|
81
|
|
|
public function edit($id) |
|
82
|
|
|
{ |
|
83
|
|
|
$data['query'] = Roles::find($id); |
|
84
|
|
|
return view('roles.edit', $data); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Update a role in the database. |
|
89
|
|
|
* |
|
90
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
91
|
|
|
*/ |
|
92
|
|
|
public function update() |
|
93
|
|
|
{ |
|
94
|
|
|
return redirect()->back(302); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Destroy a role out off the database. |
|
99
|
|
|
* |
|
100
|
|
|
* @param int $id The id in the database for the role. |
|
101
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
102
|
|
|
*/ |
|
103
|
|
|
public function destroy($id) |
|
104
|
|
|
{ |
|
105
|
|
|
Roles::destroy($id); |
|
106
|
|
|
session()->flash('message', 'Role deleted'); |
|
107
|
|
|
return redirect()->back(302); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.