Laravel, How to redirect to different login page if not login

I'm using editor middleware and customer middleware, I want to redirect every one to a different login page if not login

so for editor if anyone tried to open editor/dashboard then redirect to editor/login route and if tried to open customer dashboard then return to customer/login

Route::group(['middleware' => ['auth:web','editor'],'prefix' => 'editor'], function () {

Route::get('/dashboard', 'Editor\EditorController@index');

Middleware:

Customer:

 public function handle($request, Closure $next)
  {
    if((auth()->user()->role_id == 3)AND(auth()->user()->status == 1)){
      return $next($request);   
                    }return redirect()->intended('/')->withSuccess('You do not have access permission to Customer dashboard');
 } 

Editor:

  public function handle($request, Closure $next)
  {
    if((auth()->user()->role_id == 3)AND(auth()->user()->status == 1)){
      return $next($request);   
                   }
    return redirect()->intended('/')->withSuccess('You do not have access permission to Editor pages'); }

add in you editor middleware

 if(is_null(auth()->user())){
            return redirect('editor/login')
 }
 return $next($request);

Laravel If user is not logged redirect to login, after login redirect him , Problem is when a non authorized user visit this page it generates an error that is Route[login] not defined . How can I redirect to login or home page. ? <?php� I am using Laravel Framework 5.4.10, and I am using the regular authentication that . php artisan make:auth provides. I want to protect the entire app, and to redirect users to /themes after login. I have 4 controllers: ForgotPasswordController.php, LoginController.php, RegisterController.php and ResetPasswordController.php.

//Customer

public function handle($request, Closure $next)
{
    if(auth()->user() && (auth()->user()->role_id == CUSTOMER_ROLE_ID) && (auth()->guard('user')->user()->status == 1)) {
      return $next($request);   
    } 
    return redirect()->intended('login/customer')->withSuccess('You do not have access permission to Editor pages');
} 

//Editor
public function handle($request, Closure $next)
{
    if(auth()->user() && (auth()->user()->role_id == EDITOR_ROLE_ID) && (auth()->guard('user')->user()->status == 1)) {
      return $next($request);   
    }
    return redirect()->intended('login/editor')->withSuccess('You do not have access permission to Editor pages');
}

Laravel Middleware Redirect to Login page if not logged in, Thankfully Laravel makes this really easy, check out this route: Other ways: if //if not logged in redirect to login page automatically return� Laravel Middleware Redirect to Login page if not logged in Posted 2 years ago by shan_biswas. There is a create new post page. I want only authorized users to create

//customer
public function handle($request, Closure $next)
 {
   if(auth()->guard('user')->user()->role_id == 3 && auth()->guard('user')->user()->status == 1){
     return $next($request);   
   }
   return redirect("/");
} 

//editor
public function handle($request, Closure $next)
 {
   if(auth()->guard('user')->user()->role_id == 3 && auth()->guard('user')->user()->status == 1){
     return $next($request);   
    }
   return redirect("/"); 
}

Laravel Auto redirect if not logged in, Get code examples like "redirect to login page if not logged in in laravel guard" instantly right from your google search results with the Grepper� Want to know how to redirect user after login in your Laravel app? Then this short article will help you out! By default laravel will redirect a user to the home page like so: protected $redirectTo = '/home'; To change that default behaviour, add the following code in App/Http/Controllers/Auth/LoginController.php.

redirect to login page if not logged in in laravel guard Code Example, I was trying to figure out how I could redirect user after login based switch-case, it will redirect the user back to the login page…please, This example only focuses on the redirect part, and does not fully secure users from entering other In LoginController.php file (which is generated when you run php� Luckily, latest release of Laravel provides a convenient way to do so, let me show you how! Prerequisites. This article is based on artisans that have already setup Laravel’s pre-built Authentication with relationships. Example. This example only focuses on the redirect part, and does not fully secure users from entering other paths.

Learn how to redirect authenticated users to corresponding path in , If your application is not using Eloquent, you may use the database users of your application without setting up a dedicated "login" page. You will need two routes: one for redirecting the user to the OAuth provider, and another for receiving� That tells Laravel to redirect to the last intended page before login, otherwise go to "/home" or wherever you'd like to send them by default. Hope this helps someone else - there's not much out there on the differences between 5.2 and 5.3, and in this area in particular there are quite a few.

Authentication, There are several ways to generate a RedirectResponse instance. The simplest method is to use the global redirect helper: to redirect the user to their previous location, such as when a submitted form is invalid. return redirect()->route(' login'); Remember, you do not need to specify the full namespace to the controller� Laravel Posted 3 years ago by mbpp I created a new Middleware called "MustBeAdmin", and in my function depending of the account_type_id i give permission or not, but i notice for example when i access a page without being authenticate im redirect to "/login" route, but since my default redirect cant be this route, i need to change it, but i

Comments
  • please put your middleware code
  • it will apply on for those route which is use this middlware and make sure your auth middleware should not apply
  • Im asking about if he is not login, I mean if he copied editor/dashboard and tried to open it in other browser!!
  • you may add auth()->user() in if statement to check if user already authenticated Check updated answer
  • can you add it in ur answer? I tried this but stil back me to login page
  • Added it to my answer
  • nothing changed, still redirect me to the normal login page, I want it if this route in the editor middleware group then if the user is not login to redirect him to editor login page
  • Welcome to StackOverflow. It's good to provide code snippet as solutions, but code-only answers are considered bad practice. Please elaborate what this snippet does and how it fixes the problem.
  • where is the different of what you wrote and what I have??????????