I created a auth for my website. I have figured out that if a User is logged in he cant go back to the homepage because he is now in the dashboard. I changed everything from the generated home.blade.php to dashboard.blade.php also all related references of home by the help of Stackoverflow
Now I get a Awkward Error. If I logout from the dashboard and want to be redirect to http://localhost:8888/ (welcome.blade.php), i get http://localhost:8888/login (login.blade.php).
More awkward if I click on the navbrand on top left after logout, I am not redirecting to http://localhost:8888/ instead i get redirected to http://localhost:8888/login.
web.php
Route::group(array(['middleware'=>['guest']]), function(){
Route::get('/', function () {
return view('welcome');
});
});
Auth::routes();
// Only logged user
Route::group(array('middleware'=>'auth'), function(){
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
Route::get('/', function () {
return redirect('/dashboard');
});
});
LoginController.php
use Illuminate\Http\Request;
protected function loggedOut(Request $request) {
return redirect('/');
}
So I cant put a picture of telescope but I think i can try to recreate the Picture with text.
Expected Results: I don't know much about HTTP-Status so i made all 200
Verb| Path | Status
Here by '/' should be viewed welcome.blade.php
GET | / | 200
POST| /logout | 200
GET | /dashboard | 200
The user can't visit the Path '/' because he is now in dashboard website.
GET | / | 200
POST| /login | 200
Actual Results:
Verb| Path | Status
GET | /login | 200
GET | / | 302
POST| /logout | 302
GET | /dashboard | 200
GET | / | 302
POST| /login | 302
If you guys have any Question and want to see some more classes then please ask me. I dont know what is relevant for the error. My thought is mainly that web.php routes are wrong.
Best Regards Tobias
The mistake is that you use the same route twice.
rewrite code in web.php:
Route::get('/', HomeController@index);
Auth::routes();`
// Only logged user
Route::group(array('middleware'=>'auth'), function(){
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
});
and in HomeController write your logic:
public function index()
{
return Auth::guest() ? view('welcome') : redirect('/dashboard');
}