Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

risya's avatar
Level 1

login page not redirect to dashboard page even after it went successful

hi, i need some help here. I'm not sure what went wrong but when user login the credentials and success but it still stay at login page and not redirect to my dashboard even when the user has verified the email?

LoginController :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class LoginController extends Controller
{
    public function index()
    {
        return view('auth.login');
    }

    public function customLogin(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);

        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) {
            return redirect()->intended('dashboard')
                        ->withSuccess('You have Successfully loggedin');
        }

        return redirect("/")->withSuccess('Oppes! You have entered invalid credentials');
    }


    public function dashboard()
    {
        if(Auth::check()){
            return view('dashboard');
        }

        return redirect("/")->withSuccess('You are not allowed to access');
    }

    public function signOut() {
        Session::flush();
        Auth::logout();

        return Redirect('/');
    }
}
0 likes
9 replies
AddWebContribution's avatar

@risya The intended() method requires a call to guest() when redirecting previous to the former instead of this

 return redirect()->intended('dashboard');

do this

 return redirect()->intended(route('dashboard'));
AddWebContribution's avatar

@risya check with this might work

             return redirect()->route('dashboard');

also clear the route

   php artisan optimize:clear
AddWebContribution's avatar

@risya if its still not working

  public function customLogin(Request $request)
{
    $request->validate([
        'email' => 'required',
        'password' => 'required',
    ]);

    $credentials = $request->only('email', 'password');
   // put dd(Auth::attempt($credentials)) check is it true or not
    if (Auth::attempt($credentials)) {

        return redirect()->intended('dashboard')
                    ->withSuccess('You have Successfully loggedin');
    }

    return redirect("/")->withSuccess('Oppes! You have entered invalid credentials');
}


public function dashboard()
{
		// if above dd will get true then put dd(Auth::check()) and check
    if(Auth::check()){
        return view('dashboard');
    }

    return redirect("/")->withSuccess('You are not allowed to access');
}
risya's avatar
Level 1

web.php

Route::get('dashboard', [LoginController::class, 'dashboard'])->middleware(['auth', 'verify_email']);
Route::get('/', [LoginController::class, 'index'])->name('login');
Route::post('custom-login', [LoginController::class, 'customLogin'])->name('login.custom');
Route::get('registration', [RegisterController::class, 'registration'])->name('register-user');
Route::post('custom-registration', [RegisterController::class, 'customRegistration'])->name('register.custom');
Route::get('signout', [LoginController::class, 'signOut'])->name('signout');

Please or to participate in this conversation.