Answer the question
In order to leave comments, you need to log in
How to render a view along the same route depending on a condition?
Here is my router code
Route::group(['middleware' => 'guest'], function () {
Route::get('/', function () {
return view('layouts/login');
})->name('login');
});
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
return view('index');
})->name('index');
Route::get('/', function () {
return view('layouts/main');
})->name('main');
Route::get('/profile', function () {
return view('layouts/profile');
})->name('profile');
Route::get('/exchange', function () {
return view('layouts/exchange');
})->name('exchange');
});
Route [login] not defined.
Answer the question
In order to leave comments, you need to log in
First, learn how to create controllers.
Then read about Auth and how to find out if the user is currently logged in or not, depending on this, give different templates, and do not create "2 routes per link" because. it's impossible.
if (auth()->guest()) {
Route::group(['middleware' => 'guest'], function () {
Route::get('/', function () {
return view('layouts/login');
})->name('login');
});
} else {
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
return view('index');
})->name('index');
Route::get('/', function () {
return view('layouts/main');
})->name('main');
Route::get('/profile', function () {
return view('layouts/profile');
})->name('profile');
Route::get('/exchange', function () {
return view('layouts/exchange');
})->name('exchange');
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question