如何使用laravel中间件的except和only选项来限制路由访问?
- 内容介绍
- 相关推荐
本文共计488个文字,预计阅读时间需要2分钟。
原文示例:原文:本文实例讲述了Laravel框架中中间件+except和only的用法。分享给大众供应商参考,具体如下:except:为黑名单机制,除了show页面未经过中间件Auth过滤,其他都需要过滤。only:为白名单机制,除了show页面需要过滤,其他都不需要过滤。
改写后:本文以实例展示了Laravel框架中中间件的except和only用法。以下为具体内容:except:用于排除特定操作,如show页面无需经过Auth中间件过滤,其他操作则必须经过。only:用于指定特定操作需过滤,如show页面需过滤,其他操作则无需过滤。
本文实例讲述了laravel框架中间件 except 和 only 的用法。分享给大家供大家参考,具体如下:
except
except:为黑名单机制,除了show页面不经过中间件Auth过滤,其他都需要过滤,如果没有通过验证,则跳转到指定的页面
only
only:为白名单机制,除了edit页面需要经过中间件Auth过滤,其他都不需要过滤,如果没有通过验证,则跳转到指定的页面
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:为黑名单机制,除了show页面不经过中间件Auth过滤,其他都需要过滤,如果没有通过验证,则跳转到指定的页面
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:为白名单机制,除了edit页面需要经过中间件Auth过滤,其他都不需要过滤,如果没有通过验证,则跳转到指定的页面
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
本文共计488个文字,预计阅读时间需要2分钟。
原文示例:原文:本文实例讲述了Laravel框架中中间件+except和only的用法。分享给大众供应商参考,具体如下:except:为黑名单机制,除了show页面未经过中间件Auth过滤,其他都需要过滤。only:为白名单机制,除了show页面需要过滤,其他都不需要过滤。
改写后:本文以实例展示了Laravel框架中中间件的except和only用法。以下为具体内容:except:用于排除特定操作,如show页面无需经过Auth中间件过滤,其他操作则必须经过。only:用于指定特定操作需过滤,如show页面需过滤,其他操作则无需过滤。
本文实例讲述了laravel框架中间件 except 和 only 的用法。分享给大家供大家参考,具体如下:
except
except:为黑名单机制,除了show页面不经过中间件Auth过滤,其他都需要过滤,如果没有通过验证,则跳转到指定的页面
only
only:为白名单机制,除了edit页面需要经过中间件Auth过滤,其他都不需要过滤,如果没有通过验证,则跳转到指定的页面
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:为黑名单机制,除了show页面不经过中间件Auth过滤,其他都需要过滤,如果没有通过验证,则跳转到指定的页面
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:为白名单机制,除了edit页面需要经过中间件Auth过滤,其他都不需要过滤,如果没有通过验证,则跳转到指定的页面
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

