check()) { $action = $request->route()->getCompiled()->getStaticPrefix(); $method = $request->route()->getActionMethod(); $user = Auth::guard('sanctum')->user(); $user_id = $user->id; $uriArr = AdminMenuService::auth($user_id); if ($this->passedOrNot($action, $uriArr, $method)) { return (new ApiResponseService())->error( __('middleware.check.user_auth'), 400 ); } } return $next($request); } /** * @param $action * @param $uriArr * @param $targetMethod * @return bool */ protected function passedOrNot($action, $uriArr, $targetMethod): bool { $search = '/api/admin/'; $action = str_replace($search, '', $action); $action = str_replace('/', '.', $action); if (in_array($action, $uriArr)) { return false; } $methodArr = ['create', 'edit']; $actionArr = explode('.', trim($action)); $method = $actionArr[1] ?? ''; $newAction = $actionArr[0] ?? ''; // 短写法接口 if (empty($method)) { $targetAction = $newAction . '.' . $targetMethod; if (in_array($targetAction, $uriArr)) { return false; } } // 特殊1 $special = ['logout', 'me', 'menu']; if (in_array($newAction, $special)) { return false; } // 特殊2 $special2 = ['rule', 'uploadImage', 'search', 'targetMode', 'buildingFloorList']; if (in_array($method, $special2)) { return false; } if ($method == $methodArr[0]) { $newAction .= '.store'; } elseif($method == $methodArr[1]) { $newAction .= '.update'; } if (in_array($newAction, $uriArr)) { return false; } return true; } }