12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Http\Requests\API\File;
- use App\Models\Enums\FileObjectType;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Http\UploadedFile;
- use Illuminate\Validation\Rules\Enum;
- use Illuminate\Validation\Rules\File;
- class KeepDirectoryUploadRequest 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 = [
- "files" => "required|array",
- "folders" => "required|array",
- "object_type" => [
- "required",
- new Enum(FileObjectType::class),
- ],
- "object_id" => "min:0",
- "names" => "array",
- "folder_id" => "min:0",
- "uuid" => "max:40"
- ];
- if (! $this->request->has("object_id")) {
- $rules['uuid'] = "required|max:40";
- }
- $extensions = ['jpg','txt', 'jpeg', 'png', 'gif', 'pdf', 'xls', 'xlsx', 'zip', 'wps', 'docx', 'doc','mpp','pptx','mp4','avi','mpeg','mov'];
- if ($this->request->get("object_type") == FileObjectType::CONTAINER->value) {
- $extensions = [...$extensions, ...config("bim.extensions")];
- }
- $rules['files.*'] = [
- File::default()->max("2gb"),
- function ($attribute, UploadedFile $value, $fail) use ($extensions) {
- if (! in_array($value->getClientOriginalExtension(), $extensions) && !in_array($value->getExtension(), $extensions)) {
- $fail(sprintf("Please select the correct file, the following files are supported: %s", implode(",", $extensions)));
- }
- }
- ];
- return $rules;
- }
- }
|