M
M
Maxim Shevchenko2019-08-23 13:23:15
Laravel
Maxim Shevchenko, 2019-08-23 13:23:15

There is a route with parameters, you need to make a redirect if there are no parameters, how?

Hello everyone
Such a question is a route

Route::get('portfolio/cat/{alias?}',['uses' => 'Portfolio\[email protected]', 'as'=>'portfolioCat'])

How to make a redirect if there is no alias parameter without using a controller? Interested in whether there is a standard functionality of the framework that allows this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
oleg_ods, 2019-08-23
@MarsianinM

Make a check and register a redirect directly in the route. And for good to make middleware

K
Konstantin B., 2019-08-23
@Kostik_1993

Route::redirect()

V
Vadim Milevsky, 2019-08-24
@3gsxarakiri

In the controller method, write the following:
if ($request->route("alias") === null) {
return redirect()->route("route name");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question