File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Http \Controllers ;
4
4
5
+ use App \Http \Requests \UserStoreRequest ;
5
6
use App \Models \User ;
6
7
use Illuminate \Http \Request ;
7
8
use Inertia \Inertia ;
@@ -16,7 +17,7 @@ public function index(Request $request)
16
17
return Inertia::render ('Users/Index ' , [
17
18
'users ' => User::with ('role ' )->when ($ request ->term , function ($ query , $ term ) {
18
19
$ query ->where ('name ' , 'LIKE ' , '% ' . $ term . '% ' );
19
- })->paginate (5 ),
20
+ })->latest ()-> paginate (5 ),
20
21
]);
21
22
}
22
23
@@ -31,9 +32,11 @@ public function create()
31
32
/**
32
33
* Store a newly created resource in storage.
33
34
*/
34
- public function store (Request $ request )
35
+ public function store (UserStoreRequest $ request )
35
36
{
36
- //
37
+ User::create ($ request ->validated ());
38
+
39
+ return to_route ('users.index ' )->with ('success ' , 'User has been created! ' );
37
40
}
38
41
39
42
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Requests ;
4
+
5
+ use Illuminate \Foundation \Http \FormRequest ;
6
+
7
+ class UserStoreRequest extends FormRequest
8
+ {
9
+ /**
10
+ * Determine if the user is authorized to make this request.
11
+ */
12
+ public function authorize (): bool
13
+ {
14
+ return true ;
15
+ }
16
+
17
+ /**
18
+ * Get the validation rules that apply to the request.
19
+ *
20
+ * @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
21
+ */
22
+ public function rules (): array
23
+ {
24
+ return [
25
+ 'name ' => 'required|min:2|max:255 ' ,
26
+ 'email ' => 'required|email|min:2|max:255|unique:users ' ,
27
+ 'password ' => 'required|min:8|max:255 ' ,
28
+ 'role_id ' => 'required ' ,
29
+ ];
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ export default {
83
83
form: this .$inertia .form ({
84
84
name: ' ' ,
85
85
email: ' ' ,
86
- role_id: 1 ,
86
+ role_id: 2 ,
87
87
password: ' ' ,
88
88
})
89
89
}
You can’t perform that action at this time.
0 commit comments