mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 11:09:27 +00:00
31 lines
695 B
PHP
31 lines
695 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
|
|
* @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);
|
|
}
|
|
}
|