|string> */ public function rules(): array { $rules = []; if ($this->isMethod('post') || $this->isMethod('put')) { $rules = [ 'platform' => 'required|string|in:taobao,tmall,jd,pdd,douyin,kuaishou,weidian,youzan', 'shop_name' => 'required|string|max:100', 'app_key' => 'required|string|max:200', 'app_secret' => 'required|string|max:200', 'session_key' => 'nullable|string|max:200', 'access_token' => 'nullable|string|max:500', 'refresh_token' => 'nullable|string|max:500', 'expires_at' => 'nullable|date', 'remark' => 'nullable|string|max:500', ]; // 更新时所有字段都是可选的 if ($this->isMethod('put')) { $rules = array_map(function ($rule) { return str_replace('required|', 'nullable|', $rule); }, $rules); $rules['platform'] = 'nullable|string|in:taobao,tmall,jd,pdd,douyin,kuaishou,weidian,youzan'; } } return $rules; } /** * Get custom messages for validator errors. */ public function messages(): array { return [ 'platform.required' => '请选择平台', 'platform.in' => '平台类型不支持', 'shop_name.required' => '店铺名称不能为空', 'app_key.required' => 'App Key不能为空', 'app_secret.required' => 'App Secret不能为空', ]; } }