UploadRequest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Requests\API\File;
  3. use App\Http\Requests\RuleHelper;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Support\Facades\Storage;
  6. class UploadRequest extends FormRequest
  7. {
  8. use RuleHelper;
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. */
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  20. */
  21. public function rules(): array
  22. {
  23. return [
  24. 'file' => [
  25. 'required',
  26. // function ($attribute, $value, $fail) {
  27. // // 检查文件是否存在默认存储对象系统中
  28. // if (Storage::exists('uploads/' .date('Ym/d/'). $value->getClientOriginalName())) {
  29. // $fail('File already exists');
  30. // }
  31. // },
  32. ],
  33. 'name' => [
  34. 'nullable',
  35. 'max:150',
  36. ],
  37. 'path' => [
  38. 'nullable',
  39. ],
  40. ];
  41. }
  42. }