To redirect to the tenant login page instead of the central login page when using the auth middleware in Laravel, you can customize the redirectTo method in the RedirectIfAuthenticated middleware.
Here's how you can do it:
-
Open the
RedirectIfAuthenticatedmiddleware file located atapp/Http/Middleware/RedirectIfAuthenticated.php. -
Inside the
redirectTomethod, you can check if the user belongs to a tenant and redirect them to the tenant login page accordingly. You can use theAuth::user()method to retrieve the authenticated user and check if they have a tenant associated with them.public function redirectTo($request) { if (Auth::check() && Auth::user()->tenant) { return route('tenant.login'); // Replace 'tenant.login' with the actual route name for the tenant login page } return route('login'); // Replace 'login' with the actual route name for the central login page } -
Save the file.
Now, when the auth middleware is applied to a route, it will redirect the user to the tenant login page if they have a tenant associated with them. Otherwise, it will redirect them to the central login page.
Note: Make sure you have defined the appropriate routes for the tenant login page and the central login page in your routes file.