64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class ShopAuthRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|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不能为空',
|
|
];
|
|
}
|
|
} |