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

leo4all's avatar

Retrieving get parameter

This had been an issue for me trying to understand

I got this route

Route::get('home/{home}', 'HomeController@home');

And this action

public function home(Request $request){
   return $request->input('home');
}

Why I can't grab the {home} params that way.

I KNOW its possible to declare it thought the function params like: function home($home) / or access it like $request->home,

but the documentation say that $request->get() / $request->input() access any params $_GET or $_POST

0 likes
4 replies
jlrdw's avatar
Route::get('home/{home}', 'HomeController@home');

Is for passing with a parameter

Route::get('home', 'HomeController@home');

Is what you need

lancebutler2's avatar
Level 11

Using the Route

Route::get('home/{home}', 'HomeController@home');

You can access the {home} paramter in the controlller by

public function home(Request $request, $home){
   return $home;
}

That parameter is passed to your controller method. You don't even need that Request $request param unless you're accessing get/post params. That is NOT a get or post parameter. It's not the same as http://laravel.app/home?home=value.

It is a wildcard parameter for things like http://laravel.app/home/the-white-house

leo4all's avatar

But why if I have like this

Route::get('/home/{home}/{test}', 'HomeController@home');

And I don't declare those in the function params,

So my question again is, why the $request doesn't get the all the url params like $request->all() or explicit $request->input('home') / $request->input('test')

This is ODD for me because I though {home} or {test} are defined as Request parameters and the strange thing is that you can access like $request->home or $request->test

Please or to participate in this conversation.