Home Laravel 5.5 Getting 302 redirect error when redirecting user to homepage after login
Reply: 0

Laravel 5.5 Getting 302 redirect error when redirecting user to homepage after login

user2604 Published in June 18, 2018, 7:32 am

I have searched a lot of forums and didn't find my mistake here. I'm not very good in laravel so I'm sure I'm doing a mistake which would be obvious to more advanced developers. My page works like this. When new user first comes to the website there will be no need to login and user can view the home page. Then User registers and will be redirected to an email validation page with a link to the home page but the user isn't logged in automatically. After user confirms her email, she can go and log in. After login I want the user to be redirected to the home page if the user is a normal user and to the dashboard if the user is an Admin. Here is where the problem comes. After login I get the 302 redirection error. Below you can see my routes and different controllers I've edited. Hope I've been able to explain the problem. Thanks for any help in advance.

My web.php file

Route::get('/', ['middleware'=>'web','uses'=>'HomeController@index']);
Route::get('/home', ['middleware'=>'auth','uses'=>'HomeController@after_login']);
    return view('validate-email');
Route::get('/all', ['middleware'=>'guest','uses'=>'HomeController@index']);

My LoginController.php controller, where I've overwritten the authenticated function from the AuthenticatesUsers.php :

//   protected $redirectTo = '/home';

protected function authenticated( Request $request, $user ) {
        if($user->isAdmin == '0'){

            return redirect()->intended('/home');
        }else if($user->isAdmin == '1'){
            return redirect()->intended('dashboard.dashhome');

            return redirect()->intended('/home');

And here is my HomeController.php which handles the routes:

public function index() {
    $country = Country::all();
    return view('/home',compact('country'));

public function after_login(){
    $country = Country::all();
    return view('/home',compact('country'));
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32891 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO