DownloadRequest.php 986 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 DownloadRequest 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. 'url' => [
  25. 'required',
  26. function ($attribute, $value, $fail) {
  27. // 检查文件是否存在默认存储对象系统中
  28. if (!Storage::exists($value)) {
  29. $fail('url file does not exist');
  30. }
  31. },
  32. ],
  33. ];
  34. }
  35. }