侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

laravel框架中间件 except 和 only 的用法示例

2022-07-13 星期三 / 0 评论 / 0 点赞 / 37 阅读 / 2351 字

本文实例讲述了laravel框架中间件 except 和 only 的用法。分享给大家供大家参考,具体如下:exceptexcept:为黑名单机制,除了show页面不经过中间件Auth过滤,其他都需要过滤,如果没有通过验

本文实例讲述了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程序设计有所帮助。

广告 广告

评论区