1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Requests\API\File;
- use App\Models\Enums\FileObjectType;
- use App\Models\User;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Validation\Rules\Enum;
- use Illuminate\Validation\Rules\File;
- class FileUploadRequest 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
- {
- return [
- "files.*" => [
- 'required',
- File::types(['txt', 'jpeg', 'png', 'gif', 'pdf', 'xls', 'xlsx', 'zip', 'wps', 'docx', 'doc'])
- ->max("1gb"),
- ],
- "object_type" => [
- 'required',
- new Enum(FileObjectType::class),
- ],
- "object_id" => [
- function ($attribute, $value, $fail) {
- $exist = FileObjectType::from($this->get("object_type"))
- ->modelBuilderAllowed($value)
- ->where("company_id", Auth::user()->company_id)
- ->where('id', $value)
- ->count();
- if (! $exist) {
- $fail('Resources without permission to access.');
- }
- }
- ]
- ];
- }
- }
|