2016-08-22 10 views
0

を追加した場合、ユーザーをリダイレクトし、私は、ユーザーが、私は右の直面していますどのような課題をAuthcontroller.phpLaravel 5.2エントラスト:彼は手作業でエントラストで制限URL

protected function authenticated() 
{ 

    if(\Auth::user()->hasRole(['super_admin',])) { 
     return redirect('/dashboard'); 
    } else if(\Auth::user()->hasRole(['staff_admin'])) { 
     return redirect('/staff/dashboard'); 
    } else if(\Auth::user()->hasRole(['subadmin_admin'])) { 
     return redirect('/subadmin/dashboard'); 
    } 
} 

にこのメソッドを追加することで、ログインした後、自分のダッシュボードにリダイレクトされますどのように実装しました今は、例えばです。スタッフがログインして自分のダッシュボードにリダイレクト

domain.com/staff/dashboard

としてではなく、彼は手動でURLからスタッフを削除し、スーパー管理者ダッシュボードにアクセスしようとしならば、エントラストは、403エラーがスローされますが、私はリダイレクトするした場合彼はダッシュボードに「あなたは許可されていません」というメッセージを表示します。

RedirectIfAuthenticatedミドルウェアで同じコードを実装しようとしましたが、Nullで呼び出されたhasRoleとしてエラーが発生しました。

答えて

0

あなたのDashboardControllerはコンストラクタを追加します。

サンプルコード

class UserController extends Controller 
{ 
     public function __construct() 
     { 
      $this->middleware(['role:super_admin']); 
     } 

     public function index() 
     { 
     return view('dashboard'); 
     } 
} 

すると、エラーフォルダがそうのような403.blade.php追加:

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Be right back.</title> 

     <link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css"> 

     <style> 
      html, body { 
       height: 100%; 
      } 

      body { 
       margin: 0; 
       padding: 0; 
       width: 100%; 
       color: #B0BEC5; 
       display: table; 
       font-weight: 100; 
       font-family: 'Lato', sans-serif; 
      } 

      .container { 
       text-align: center; 
       display: table-cell; 
       vertical-align: middle; 
      } 

      .content { 
       text-align: center; 
       display: inline-block; 
      } 

      .title { 
       font-size: 72px; 
       margin-bottom: 40px; 
      } 
     </style> 
    </head> 
    <body> 
     <div class="container"> 
      <div class="content"> 
       <div class="title">You are not authorized.</div> 
      </div> 
     </div> 
    </body> 
</html> 
+0

のNop!私は403エラーページを取得するよう求めていない。私が望むのは、彼が手作業でURLを変更した後、ダッシュボードにリダイレクトする方法で、デッド403ページを表示する方法です。私は疑問を持っています。 – Tarunn

+0

vendor/zizaco/entrust/src/Entrust/Middleware/EntrustRole.phpのhandleメソッドでオーバーライドできます。 –

関連する問題