user(); if (!$user || AdminPageAccess::hasFullAccess($user)) { return $next($request); } $path = strtolower(trim($request->path(), '/')); if (str_starts_with($path, 'admin/')) { $path = substr($path, strlen('admin/')); } if ($path === 'me' || $path === 'me/update') { return $next($request); } $method = strtoupper($request->method()); $action = null; if (in_array($method, ['GET', 'HEAD', 'OPTIONS'], true)) { if (preg_match('#/active(/|$)#', $path)) { $action = 'edit'; } } elseif ($method === 'DELETE') { $action = 'delete'; } elseif (in_array($method, ['PUT', 'PATCH'], true)) { $action = 'edit'; } elseif ($method === 'POST' && !AdminPageAccess::isReadPost($path)) { $action = 'edit'; } if ($action === null) { return $next($request); } $page = (string) $request->header('X-Admin-Page', ''); if ($page === '' || !AdminPageAccess::allows($user, $page, $action)) { $message = $action === 'delete' ? 'شما مجوز حذف در این صفحه را ندارید' : 'شما مجوز ویرایش در این صفحه را ندارید'; return response()->json(['message' => $message], 403); } return $next($request); } }