Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if parameter is used in url laravel

I’m trying to check if a parameter name is included in a specific url like this: http://127.0.0.1:8000/box?size[eq]=200

I want to retrieve the name "size[eq]" in my laravel controller but it keeps returning false.

This is the code I’m using:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public function index(Request $request)
    {
 
      dd($request->has("size[eq]"));
    
     }

>Solution :

That is an array named size with an index named eq. It isn’t an actual string on the server side. Most of Laravel’s functions use the "dot notation" for dealing with nested elements. So for what would be $requestData['size']['eq'] would be:

$request->has('size.eq');

If you want to retrieve that value you would also use "dot notation":

$request->input('size.eq');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading