- Forums
- laravel
- Laravel Validate Directly From Controller File Instead Of A Request File
this example shows how you validate a method in a controller class without another Request file. [5185], Last Updated: Mon Jun 24, 2024
cathy
Sun Aug 20, 2023
0 Comments
262 Visits
Forget about using a separate Request file in Laravel. You can do it from within the Laravel Controller file like this:
NOTICE: It is not recommended to do this, its better to use a file. See Video Below.
public function store(Request $request, User $user){
$data = $request->validate([
'name' => ['required', 'string','max:100'],
]);
$user ->update{$data};
return response()->json($user, 200);
}
Resource:
9V9BUHtvwXI
Why not do this.
3P2uNeY9Azs