$id]; $validator = Validator::make($data, [ 'id' => 'required|numeric' ], [ 'id.required' => __('validation.id_empty'), 'id.numeric' => __('validation.id_numeric') ]); if ($validator->fails()) { throw new ValidationException($validator); } if (!$model::query()->where('id', $id)->exists()) { throw new Exception(__('exception.exception_handler.resource')); }; } /** * 功能显示权限 * @param string $className * @param array $auth * @return int[] * @throws InvalidArgumentException */ protected function methodShow(string $className, array $auth = []): array { $user = Auth::guard('sanctum')->user(); $methodAuthArr = AdminMenuService::auth($user->id); $authArr = [ $className . '/show' => 0, $className . '/store' => 0, $className . '/update' => 0, $className . '/destroy' => 0, ]; $newArr = []; foreach ($authArr as $authKey => $value) { if (in_array($authKey, $methodAuthArr)) { $authArr[$authKey] = 1; } $key = explode('/',$authKey); $newArr[$key[1]] = $authArr[$authKey]; } if ($auth) { $newArr = array_merge($newArr, $auth); } return $newArr; } }