laravel框架中間件 except 和 only 的用法示例
本文實(shí)例講述了laravel框架中間件 except 和 only 的用法。分享給大家供大家參考,具體如下:
except
except:為黑名單機(jī)制,除了show頁面不經(jīng)過中間件Auth過濾,其他都需要過濾,如果沒有通過驗(yàn)證,則跳轉(zhuǎn)到指定的頁面
only
only:為白名單機(jī)制,除了edit頁面需要經(jīng)過中間件Auth過濾,其他都不需要過濾,如果沒有通過驗(yàn)證,則跳轉(zhuǎn)到指定的頁面
except用法:
class UserController extends Controller { public function __construct() { $this->middleware('auth', ['except' => 'show']); } public function show(User $user) { return view('users.show', compact('user')); } public function edit(User $user) { return view('users.edit', compact('user')); } }
except:為黑名單機(jī)制,除了show頁面不經(jīng)過中間件Auth過濾,其他都需要過濾,如果沒有通過驗(yàn)證,則跳轉(zhuǎn)到指定的頁面
only用法:
class UserController extends Controller { public function __construct() { $this->middleware('auth', ['only' => 'edit']); } public function show(User $user) { return view('users.show', compact('user')); } public function edit(User $user) { return view('users.edit', compact('user')); } }
only:為白名單機(jī)制,除了edit頁面需要經(jīng)過中間件Auth過濾,其他都不需要過濾,如果沒有通過驗(yàn)證,則跳轉(zhuǎn)到指定的頁面
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。
相關(guān)文章
thinkphp數(shù)據(jù)查詢和遍歷數(shù)組實(shí)例
這篇文章主要介紹了thinkphp數(shù)據(jù)查詢和遍歷數(shù)組的方法,包括數(shù)據(jù)庫的DSN方法配置、CURD操作方法以及模板的遍歷數(shù)組等技巧,具有一定的借鑒價值,需要的朋友可以參考下2014-11-11PHP使用array_multisort對多個數(shù)組或多維數(shù)組進(jìn)行排序
這篇文章主要介紹了PHP使用array_multisort對多個數(shù)組或多維數(shù)組進(jìn)行排序,需要的朋友可以參考下2014-12-12PHP安裝threads多線程擴(kuò)展基礎(chǔ)教程
php5.3或以上,且為線程安全版本。apache和php使用的編譯器必須一致,通過phpinfo()查看Thread Safety為enabled則為線程安全版,通過phpinfo()查看Compiler項(xiàng)可以知道使用的編譯器,本文給大家介紹PHP安裝threads多線程擴(kuò)展基礎(chǔ)教程,需要的朋友參考下2015-11-11