I'm working with Laravel 5 API. I have a few methods with similar request parameters
For example to check the licence status or get the settings file you need to provide the ?serial=licence_serial_number parameter.
I need to return 400 error code, when the user didn't provide the serial parameter, and 403 error code, when the user is trying to get information about the licence of another user.
What is the best practice to organise validation and error handling of these kind of requests?
- Should I make a middleware to check if the user has provided
?serial? - Or should I make a different Laravel 5
FormRequestclass for every method? - Or should I validate it directly in a controller with:
if (..) {return response()->json([..], 400);}