<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>权限 on 施国鹏 (seth-shi)</title><link>https://sethix.com/zh-cn/tags/%E6%9D%83%E9%99%90/</link><description>Recent content in 权限 on 施国鹏 (seth-shi)</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 17 Oct 2018 16:12:05 +0800</lastBuildDate><atom:link href="https://sethix.com/zh-cn/tags/%E6%9D%83%E9%99%90/index.xml" rel="self" type="application/rss+xml"/><item><title>路由权限控制中，一个分页列表权限能同时控制所有列表权限</title><link>https://sethix.com/zh-cn/posts/2018101716/</link><pubDate>Wed, 17 Oct 2018 16:12:05 +0800</pubDate><guid>https://sethix.com/zh-cn/posts/2018101716/</guid><description>最近在写api在写权限控制时候遇到了一个问题。
还是原来的控制权限的方法Laravel中使用路由控制权限(不限于Laravel，只是一种思想)
有这么两个路由别名：
城市列表带分页：cities.index，所有城市:cities.index.all
这是两个权限，但是为了用户只分配了cities.index的权限，也能同时拥有cities.index.all的权限，
因为这两个都属于列表，这是正常的逻辑，所以需要我们在验证这一点点小修改。
&amp;lt;?php namespace App\Http\Middleware; use App\Models\Permission; use App\Models\User; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class AdminPermission { /** * 先获取当前路由的名字 * 查询当前路由是否需要权限访问 * 通过 or 权限不足 * * @param Request $request * @param Closure $next * @return mixed */ public function handle($request, Closure $next) { $route = Route::currentRouteName(); // 这条路由没有名字 if (is_null($route)) { return $next($request); } // 这个路由是否是以 all 结尾的 if (ends_with($route, &amp;#39;.</description></item><item><title>Laravel中使用路由控制权限(不限于Laravel，只是一种思想)</title><link>https://sethix.com/zh-cn/posts/2018032712/</link><pubDate>Tue, 27 Mar 2018 12:53:51 +0800</pubDate><guid>https://sethix.com/zh-cn/posts/2018032712/</guid><description>Start 权限设计是后台管理很重要的一个功能，所以要好好设计。 PHP 已经有很多这方面的packages了，就不用我们重复造轮子了。当然，如果你愿意可以从头开始~
PS 以前做权限认证的方式有好几种，我说说常用的两种吧！
每一个页面认证当前需要的权限一次 在统一的地方（中间件）验证 先上一下简单的表结构(只保留重要的信息)数据库的模型 ER 图 数据库模型图 (ps:这个设计中，用户不会直接拥有权限，只能通过角色继承权限。有很多packages会提供用户可以直接拥有权限功能) Model 模型关联关系处理：
User 模型 &amp;lt;?php namespace App\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ &amp;#39;password&amp;#39;, &amp;#39;remember_token&amp;#39;, ]; // 用户和角色的模型关联关系 public function roles() { return $this-&amp;gt;belongsToMany(Role::class); } /**************************************** * 封装一个方法方便使用 * 1. 需要的权限 * 2.</description></item></channel></rss>