You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Models\Collection;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. class FileStoreRequest extends FormRequest
  6. {
  7. private $collection = null;
  8. public function __construct()
  9. {
  10. $this->collection = Collection::where('name',$this->collection_name)->get();
  11. }
  12. /**
  13. * Determine if the user is authorized to make this request.
  14. *
  15. * @return bool
  16. */
  17. public function authorize()
  18. {
  19. return true;
  20. }
  21. private function getExts()
  22. {
  23. return implode(",",$this->collection->exts);
  24. }
  25. private function getMimeTypes()
  26. {
  27. return implode(",",$this->collection->mimetypes);
  28. }
  29. // private function getExt()
  30. // {
  31. // return implode(",",$this->collection->ext);
  32. // }
  33. /**
  34. * Get the validation rules that apply to the request.
  35. *
  36. * @return array<string, mixed>
  37. */
  38. public function rules()
  39. {
  40. return [
  41. "ext" => ["mimes:" . $this->getExts],
  42. "memetype" => ["mimetypes:" . $this->getMimeTypes],
  43. "width"=> [''],
  44. "height"=> [''],
  45. "file_size"=> [''],
  46. ];
  47. }
  48. }