A
A
Alexey2017-09-29 14:06:57
Laravel
Alexey, 2017-09-29 14:06:57

How to check get parameter in route?

Good afternoon. There is the following code in the route:

Route::get('catalog/{mode?}', '[email protected]');

When I request /catalog?mode=param, then in the controller [email protected] I check the value of the get parameter and display what I need.
And how to check directly in the route to the same address, only to another controller?
It doesn't work like this:
Route::get('catalog/?mode=setting', '[email protected]');

And it's a lot to put everything in the CatalogController. How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2017-09-29
@ffg001

So let's start in the first case

Route::get('catalog/{mode?}', '[email protected]');
you still use a variable as a parameter of the router (path), the question mark tells us that it is optional, maybe, or maybe not. Well, yes, in fact, this is part of the get requests.
Further, in general, read this .
You can use the helper function request():
Somewhere in the body of the SettingController, in the body of the index method
***
$mode = request()->mode;
***

In general, why are you doing this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question