12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Http\Requests\API\Library;
- use App\Http\Requests\RuleHelper;
- use App\Models\Enums\LibraryACL;
- use App\Models\Enums\LibraryType;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Validation\Rule;
- use Illuminate\Validation\Rules\Enum;
- class CreateOrUpdateRequest extends FormRequest
- {
- use RuleHelper;
- /**
- * 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 = [
- 'name' => 'required',
- 'type' => [
- 'required',
- new Enum(LibraryType::class)
- ],
- 'acl' => [
- 'required',
- new Enum(LibraryACL::class),
- ],
- 'whitelist' => $this->usersCompanyRules(),
- ];
- switch ($this->request->get("type")) {
- case LibraryType::ASSET->value:
- $rules['asset_id'] = [
- 'required',
- Rule::exists('assets', 'id')->where($this->userCompanyWhere()),
- ];
- break;
- case LibraryType::PROJECT->value:
- $rules['project_id'] = [
- 'required',
- Rule::exists('projects', 'id')->where($this->userCompanyWhere()),
- ];
- break;
- }
- return $rules;
- }
- }
|