alexeymezenin / laravel-best-practices

Laravel best practices
11.24k stars 2.37k forks source link

Query Parameter Validation #170

Open arian-sakhaei opened 1 year ago

arian-sakhaei commented 1 year ago

Hi, Can you help me on how to use FormRequest to validate query parameters?

here's a my code:

Route:

Route::controller(UserController::class)->group(function () {
    Route::get('get-user/{id}', 'getUser');
});

Controller:

public function getUser(UserController $request) // or => (UserController $id)
{
// can't get the parameter I expect
}

and then there is a EditUserRequest class extending FormRequest which I wish to use! tnx for the help in advance.

alexoleynik0 commented 12 months ago

Hi, is this still relevant? The best way I figured out on how to do validation on route's values is to merge them into request body in your UserEditRequest's prepare method override (or something like that, can't check and share the code right now - see the class you're extending).