简体   繁体   English

Laravel,如果没有登录,如何重定向到不同的登录页面

[英]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添加你的editor中间件

 if(is_null(auth()->user())){
            return redirect('editor/login')
 }
 return $next($request);
//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');
}
//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("/"); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM