Files
ProxyPanel/app/Http/Middleware/Permission.php
兔姬桑 2a4bf701f2 Add RBAC Module & More
1. 添加RBAC的权限&角色控制件;
2. 将用户‘is_admin’转换为角色;
3. 针对RBAC对管理页面进行定制化处理;
4. 加深layout分层处理;
5. 修改部分路由名称;
6. 分解路由文件至多文件;
2020-12-11 16:14:30 +08:00

32 lines
725 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Spatie\Permission\Exceptions\UnauthorizedException;
class Permission
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (app('auth')->guard($guard)->guest()) {
throw UnauthorizedException::notLoggedIn();
}
$route = request()->route()->getName();
if (app('auth')->guard($guard)->user()->can($route)) {
return $next($request);
}
throw UnauthorizedException::forPermissions((array) $route);
}
}