1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Actions\GetUserRoles; |
6
|
|
|
use App\Events\Admin\NewUserCreated; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use App\Http\Requests\User\UserRequest; |
9
|
|
|
use App\Models\User; |
10
|
|
|
use App\Models\UserRoles; |
11
|
|
|
use App\Models\UserSetting; |
12
|
|
|
use App\Models\UserSettingType; |
13
|
|
|
use Illuminate\Http\Request; |
14
|
|
|
use Illuminate\Support\Facades\Auth; |
15
|
|
|
use Inertia\Inertia; |
16
|
|
|
|
17
|
|
|
class UserController extends Controller |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Display a listing of the resource. |
21
|
|
|
* |
22
|
|
|
* @return \Illuminate\Http\Response |
23
|
|
|
*/ |
24
|
|
|
public function index() |
25
|
|
|
{ |
26
|
|
|
// |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Show the new user form |
31
|
|
|
*/ |
32
|
|
|
public function create() |
33
|
|
|
{ |
34
|
|
|
$this->authorize('create', User::class); |
35
|
|
|
|
36
|
|
|
return Inertia::render('Admin/User/Create', [ |
37
|
|
|
'roles' => (new GetUserRoles)->run(Auth::user()), |
|
|
|
|
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Store a newly created user |
43
|
|
|
*/ |
44
|
|
|
public function store(UserRequest $request) |
45
|
|
|
{ |
46
|
|
|
$newUser = User::create($request->toArray()); |
47
|
|
|
|
48
|
|
|
// Add the users settings data |
49
|
|
|
$settings = UserSettingType::all(); |
50
|
|
|
foreach($settings as $setting) |
51
|
|
|
{ |
52
|
|
|
UserSetting::create([ |
53
|
|
|
'user_id' => $newUser->user_id, |
54
|
|
|
'setting_type_id' => $setting->setting_type_id, |
55
|
|
|
'value' => true, |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
event(new NewUserCreated($newUser)); |
60
|
|
|
return back()->with([ |
61
|
|
|
'message' => 'New User Created', |
62
|
|
|
'type' => 'success', |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Display the specified resource. |
68
|
|
|
* |
69
|
|
|
* @param int $id |
70
|
|
|
* @return \Illuminate\Http\Response |
71
|
|
|
*/ |
72
|
|
|
public function show($id) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
// |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Show the form for editing the specified resource. |
79
|
|
|
* |
80
|
|
|
* @param int $id |
81
|
|
|
* @return \Illuminate\Http\Response |
82
|
|
|
*/ |
83
|
|
|
public function edit($id) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
// |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Update the specified resource in storage. |
90
|
|
|
* |
91
|
|
|
* @param \Illuminate\Http\Request $request |
92
|
|
|
* @param int $id |
93
|
|
|
* @return \Illuminate\Http\Response |
94
|
|
|
*/ |
95
|
|
|
public function update(Request $request, $id) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
// |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Remove the specified resource from storage. |
102
|
|
|
* |
103
|
|
|
* @param int $id |
104
|
|
|
* @return \Illuminate\Http\Response |
105
|
|
|
*/ |
106
|
|
|
public function destroy($id) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
// |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|