-
Notifications
You must be signed in to change notification settings - Fork 20
/
UserController.php
58 lines (44 loc) · 1.25 KB
/
UserController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Http\Requests\EditUserRequest;
use App\Http\Requests\CreateUserRequest;
class UserController extends Controller
{
public function index()
{
$withDeleted = null;
if (in_array(request('deleted'), User::FILTER) && request('deleted') === 'true') {
$withDeleted = true;
}
$users = User::with('roles')
->when($withDeleted, function ($query) {
$query->withTrashed();
})
->paginate(20);
return view('users.index', compact('users', 'withDeleted'));
}
public function create()
{
return view('users.create');
}
public function store(CreateUserRequest $request)
{
User::create($request->validated());
return redirect()->route('users.index');
}
public function edit(User $user)
{
return view('users.edit', compact('user'));
}
public function update(EditUserRequest $request, User $user)
{
$user->update($request->validated());
return redirect()->route('users.index');
}
public function destroy(User $user)
{
$user->delete();
return redirect()->route('users.index');
}
}