12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Http\Requests\API\File;
- use App\Http\Requests\RuleHelper;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Storage;
- class UploadRequest extends FormRequest
- {
- use RuleHelper;
- /**
- * 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
- {
- return [
- 'file' => [
- 'required',
- 'max:52428800',
- ],
- 'fileName' => [
- 'nullable',
- 'max:150',
- function ($attribute, $value, $fail) {
- // 检查文件是否存在默认存储对象系统中
- if (Storage::exists('uploads/' .date('Ymd/'). $value)) {
- $fail('File already exists');
- }
- },
- ]
- ];
- }
- }
|