laravel5.1 - php laravel 如何優雅的寫一個登入驗證的 中介軟體魚路由

來源:互聯網
上載者:User
看了 laravel 的auth 的登入中介軟體;

目前auth 對應的 user 表 已經使用了;

現在需要 建立一直表 Operator ; 這個是一個前台操作員的登入表模型

Route::get('operator/index_1.html', ['middleware' => 'OperatorAuth', OperatorController@indexOne);Route::get('operator/index_2.html', ['middleware' => 'OperatorAuth', OperatorController@indexTwo);

訪問這個頁面是需要進行 OperatorAuth 中間驗證的

有2類操作員, 分別訪問以上2個 路由

OperatorAuth 這個中介軟體該如何寫呢 需要繼續 laravel auth 嗎

另外 問一下 流程 ;

訪問者 訪問 operator/index_1.html 經過中介軟體OperatorAuth 登入 ,登入成功後 再返回operator/index_1.html

訪問者 訪問 operator/index_2.html 經過中介軟體OperatorAuth 登入 ,登入成功後 再返回operator/index_2.html

這個中介軟體驗證成功後返回 訪問的地址 ; 這個在 中介軟體裡 如何寫呢?

有沒有大神 貼一下 laravel 書寫的 優雅代碼呢? 看見好多 laravel 書寫的代碼都很漂亮呀,自己寫的代碼感覺好醜呀。

求一下大神指導一下,智商比較低,望 ,見諒菜鳥的 無知 嘿嘿.

回複內容:

看了 laravel 的auth 的登入中介軟體;

目前auth 對應的 user 表 已經使用了;

現在需要 建立一直表 Operator ; 這個是一個前台操作員的登入表模型

Route::get('operator/index_1.html', ['middleware' => 'OperatorAuth', OperatorController@indexOne);Route::get('operator/index_2.html', ['middleware' => 'OperatorAuth', OperatorController@indexTwo);

訪問這個頁面是需要進行 OperatorAuth 中間驗證的

有2類操作員, 分別訪問以上2個 路由

OperatorAuth 這個中介軟體該如何寫呢 需要繼續 laravel auth 嗎

另外 問一下 流程 ;

訪問者 訪問 operator/index_1.html 經過中介軟體OperatorAuth 登入 ,登入成功後 再返回operator/index_1.html

訪問者 訪問 operator/index_2.html 經過中介軟體OperatorAuth 登入 ,登入成功後 再返回operator/index_2.html

這個中介軟體驗證成功後返回 訪問的地址 ; 這個在 中介軟體裡 如何寫呢?

有沒有大神 貼一下 laravel 書寫的 優雅代碼呢? 看見好多 laravel 書寫的代碼都很漂亮呀,自己寫的代碼感覺好醜呀。

求一下大神指導一下,智商比較低,望 ,見諒菜鳥的 無知 嘿嘿.

第一,命令列:

php artisan make:middleware FrontEndOperatorAuth

第二,找到app/Http/Middlewares檔案夾下面的FrontEndOperatorAuth.php,在handle()方法寫你的邏輯:

  public function handle($request, Closure $next)    {        $user = $request->user();        if ( $user && $user->isOperator() ) {            return $next($request);        }        return redirect()->back();    }    

第三,在User.php中增加isOperator():

public function isOperator(){       // your logic goes here}

btw,希望修改一下錯別字。

然後我最近上線了一個laravel的社區:Laravist,有什麼laravel相關的問題可以到這裡來問我

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.