看了 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相關的問題可以到這裡來問我