Answer the question
In order to leave comments, you need to log in
How to force the vendor middleware to be executed before the execution of the native Request class?
So, I create the Request class with the make:request artisan command in order to validate the request data inside it. From the documentation it is clear that inside the request class created in this way there is an authorize method, by redefining the body of which, you can make preliminary boolean checks related to authorization.
class SuggestionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user() && $this->user()->hasRole('sales manager');
// return true;
}
}
Route::post('/suggest', [SuggestionController::class, 'store'])
->middleware('auth:sanctum');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question