vegasys
234
5
Laravel

How to validate URL query parameters?

Posted 2 months ago by vegasys

Hello,

https://youtu.be/-1Hh-Hj4ZyU?t=648

Here it says :

if ($month = $filters['month']) { // some query scope }

When I run the app, it raises following error: Undefined index 'month'

I can solve the error if I change it to: if ( isset($filters['month']) ) { // some query scope }

Why does it work on the video but not in my app? (Laravel 5.5)

if I go to my home at /home, it won't work anymore, unless I go to /home?month=&year=

Also, how do I validate url parameters? If I go to /home?month=''''''&year= It will raise an error because Carbon expects a month but I provided single quotes. How do I validate the $_GET['month'] before it enters within the $query->whereMonth()?

Info aby my setup/code: Laravel 5.5. No custom code so far. I just followed the whole video tutorial so far (I'm learning). All my controllers and models are fully similar to the Laracast video above.

Regards,

Please sign in or create an account to participate in this conversation.