Files
test_test/app/Http/Middleware/CheckPermission.php
2026-04-06 18:44:02 +05:00

33 lines
866 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Auth;
class CheckPermission
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, string $permission): Response
{
if (!Auth::check()) {
abort(403, 'Для доступа необходимо авторизоваться');
}
/** @var \App\Models\User $user */
$user = Auth::user();
if (!$user->hasPermission($permission)) {
abort(403, 'У вас нет прав для доступа к этой странице');
}
return $next($request);
}
}