Files
ProxyPanel/app/Http/Middleware/Permission.php
兔姬桑 f67bcf623d code improve
Apply fixes from StyleCI
2022-01-16 22:57:48 +08:00

33 lines
753 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
* @param null $guard
* @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);
}
}