Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ronaldo100's avatar

passing GET parameters from web.php to the controller to the view

Hello!

I would like to pass GET parameters from the URL to the Routes (web.php) and from the Routes to the Controller and from the Controller to the View.

So far, I have fully understood how to do it, when the URL looks like this:

https://******.com/foobar/111/222/333/

In this case, I would do it like this:

/routes/web.php

Route::get('/foobar/{aaa}/{bbb}/{ccc}', [FooController::class, 'foobar']);

app/Http/Controllers/FooContoller.php

public function foobar($aaa, $bbb, $ccc)
{
return view('foobar', compact('aaa', 'bbb', 'ccc'));
}

/resources/views/foobar.blade.php

aaa: {{ $aaa }}<br>
bbb: {{ $bbb }}<br>
ccc: {{ $ccc }}<br>

QUESTION 1

Just to be sure: Is everything I wrote above correct and following best practice?

Question 2

HOW would I do it, when the GET parameters looked like this?

https://******.com/foobar/?a=111&b=222&c=333

Reminder: In my example above, I used / / / to separate the values.

Now, I am using ? and &

I have only managed to figure out the ROUTES (web.php) so far in two different versions:

Option 1:

Route::get('/foobar', function(Request $request)
{
return $request->a." ".$request->b." ".$request->c;
});

Option 2:

Route::get('/blog', function()
{
return request('a')." ".request('b')." ".request('c');
});

However, I do NOT want to return the GET parameters in the ROUTE (web.php)

What I want is to pass the GET parameters from the URL to the Routes (web.php) and from the Routes to the Controller and from the Controller to the View (as I did above with the / / / version)

In my first example where I called the website like https://******.com/foobar/111/222/333/, I managed to pass the values all the way to the view.

But in the second attempt where I go with https://******.com/foobar/?a=111&b=222&c=333 I got stuck in the routes (web.php) and failed to pass it any further.

Please tell me, how I can pass the https://******.com/foobar/?a=111&b=222&c=333 parameters all the way to the view!

Thank you!

Yours Ronaldo

0 likes
6 replies
Sinnbeck's avatar

Question 1. Yes that is completely correct

Question 2.

In a controller method I would do this

public function foobar(Request $request)
{
    $a = $request->input('a');
    $b = $request->input('b');
    $c = $request->input('c'); 
return view('foobar', compact('a', 'b', 'c'));
}
Ronaldo100's avatar

Dear @Sinnbeck,

thank you very much for your answer!

Please allow me to ask some follow-up questions:

A)

What does ->input() do, and why do we need it in your code sample?

We did not use it for the other way of passing parameters via /aaa/bbb/ccc/

Has this to do with the way we pass in the parameters using ? and & ?

I tried to find input() in the Laravel 9 docs (Helpers section) but I couldn't find it.

B)

How could we rewrite your code so it uses the request() helper rather than the Request object?

C)

Please kindly tell me, what code you would place in the Routes (web.php).

Your code sample (thanks for that, again) only shows the code for the Controller.

Unfortunately, I don't know how to pass the variables that we received via ? and & from the Routes (web.php) into the Controller using the ? and & way of defining parameters.

Thank you very much in advance!

Yours Ronaldo

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Ronaldo100 Let me try and answer :)

A). ->input() is just a helper function to get the data from either the url parameters (?a=foo) or from the data in a POST/PUT request. It does the same as ->a but it allows you to specify a nice fallback ->input('a', 300)

It is found on this page: https://laravel.com/docs/9.x/requests#accessing-the-request

B) Personally I prefer injection over helper functions. I believe this is the default for most projects :) But it would be written like request()->input('a')

C) You dont pass them. Only things that are part of the url path needs to be defined

Route::get('foobar', [FoobarController::class, 'foobar']);

This is all you need. Parameters will never be speficied. If you want to make sure they are present, you use validation: https://laravel.com/docs/9.x/validation

1 like
Sinnbeck's avatar

If the question is answered please mark a best answer to set the thread as solved

1 like

Please or to participate in this conversation.