Answer the question
In order to leave comments, you need to log in
How to redirect to different route from web.php file in laravel?
Hello.
I have a variable in the session based on the value of which I want to determine which route to call and where to redirect the user. For example, a variable from car brands.
Route::get('/', function (Request $request) {
$brand = $request->session()->get('brand'); // Пользователь попадает на домашнюю если установлена "brand"
if ($brand = "VAG") { redirect to vag controller } // перенаправить на vag
if ($brand = "BMW") { redirect to bmv controller } // перенаправить на bmv
if ($brand = "VOLVO") { redirect to volvo controller } // перенаправить на volvo
return view('layouts.layout'); }); // если переменная не определена то вернуть страницу по умолчанию.
Route::get('/bmw','[email protected]');
Route::get('/vag', '[email protected]');
Route::get('/volvo', '[email protected]');
Answer the question
In order to leave comments, you need to log in
It's pretty simple:
Route::get('/', function () {
return redirect('/bmw');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question