How Do You Validate GET Requests in Laravel?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this video will be a typical one I will read the article from laravel dailycom it's free it's available in the description below the link but I thought it would be so important that I want to have it as video version as well but was kind of too lazy so to speak to recreate all those scenarios I better focus on more videos and in this case we'll just read how to validate get parameters so when talking about validation we always almost always talk about post validation put validation and delete validation but these parameters also should be validated and there are various ways to do that so let me demonstrate so if we scroll down the article the first option is to have request helper Global helper or you may have it as a parameter of your controller you may provide the default value so if you don't provide the default value and for example pass that as order by the MySQL would throw an error and you can avoid that by providing default back value if no parameter is passed but of course it's only kind of partial validation because it's validated from empty value but not validated from any other value so here are other options request validate so you may pass request as I said as a parameter in the controller and nothing is really stopping you to have request validate on get request it doesn't have to be form request in fact you can use form request even without the form so in here for example you have rule in ascending or descending and put request validate or here below I'm showing that you can use form request as well so you have a form request which you use instead of request in the index the only downside of this approach is that if the validation appears in laravel then it automatically redirects back to previous page or throws 422 error status code 422 in API so you need to additionally handle those situations as well and then finally in the routes you may even produce the code that would not allow the code to get to the controller like this so if you have a certain rule that can be expressed as a regular expression you may have route get parameter parameter name and then regular expression value in case of mismatch it would throw 404 error as not matching that route and also larval provides a bit of help with helpers like where number instead of having that 0 to 9 manually here so yeah this is a quick video based on a free article but I thought it's a good discussion how do you validate the get parameters and how do you do that if you do use something like that how do you cache that validation exception share your experience let's discuss in the comments and see you guys in other videos
Info
Channel: Laravel Daily
Views: 5,680
Rating: undefined out of 5
Keywords:
Id: lre91RhYCpA
Channel Id: undefined
Length: 2min 51sec (171 seconds)
Published: Sun Jun 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.