Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73875

Laravel not logging in the user at all. (Login route keeps redirecting back)

$
0
0

I have a problem when I log in a user, it won't redirect it properly. I have followed this video: https://www.youtube.com/watch?v=atWUeGBIAAM&list=PL55RiY5tL51oloSGk5XdO2MGjPqc0BxGV&index=4

and this is my code:

 public function postSignIn(Request $request) {

    $this->validate( $request, [
        'email' => 'required|email',
        'password' => 'required',
    ]);

    if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
        session()->flash('message', 'You are logged in!.');
        return redirect()->route('dashboard');
    }
    return redirect()->back();
}

This is my authentication method:

protected function redirectTo($request)
{
    if (! $request->expectsJson()) {
        return route('welcome');
    }
}

The register user works fine and prompts the user to the dashboard. I want to be logged in users to be able to see the dashboard, and guests to be redirected to the 'welcome' view.

This is my dashboard route:

Route::get('dashboard', 'UserController@getDashboard')->name('dashboard')->middleware('auth');

Viewing all articles
Browse latest Browse all 73875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>