feat:implement permissions for admin side

This commit is contained in:
2026-08-19 13:29:48 +03:30
parent 3b98de3f01
commit 4b453fdcff
2 changed files with 79 additions and 0 deletions
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class AdminPermissionMiddleware
{
/**
* Handle an incoming request.
*
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next, string $permission): Response
{
$admin = auth('admin')->user();
if (!$admin) {
abort(403);
}
$hasPermission = $admin->permissions()
->where('name', $permission)
->exists();
if (!$hasPermission) {
abort(403, 'شما اجازه دسترسی به این بخش را ندارید.');
}
return $next($request);
}
}