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

Ligonsker's avatar

Index page - redirect to different pages (login, welcome) depending on auth status

What is a proper way to display the base URL of the app (/) for 2 different pages, depending if the user is logged in or not?

so if a user enters the base URL and he's not logged in, it will show the login.blade.php page (but still display the base URL), and if he is logged in, it will show welcome.blade.php, but still on the base URL

0 likes
5 replies
MohamedTammam's avatar
Level 51

In your controller

if(auth()->check()) {
	// Return a page for authenticated users
} else {
	// Return a page for guests
}
1 like
Ligonsker's avatar

@MohamedTammam ty, But in my case I currently have 2 different controllers for each. At first I thought to do this check in web.php but now I think doing this condition checking in web.php is not a good idea?

Or it's OK if I just put this in web.php:

Route::get('/'), function () {
    if (auth()->check()) {
        // 
    } else {
        // 
    }
}
Ligonsker's avatar

@MohamedTammam Ok, then I will need to update the code in other places :) Btw why is it not good to do what I wrote above?

Please or to participate in this conversation.