123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Http\Requests\API\Container;
- use App\Http\Requests\CustomFieldRuleHelper;
- use App\Http\Requests\NamingRuleHelper;
- use App\Http\Requests\RuleHelper;
- use App\Models\Enums\ContainerACL;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Validation\Rule;
- use Illuminate\Validation\Rules\Enum;
- class CreateOrUpdateRequest extends FormRequest
- {
- use RuleHelper, CustomFieldRuleHelper, NamingRuleHelper;
- /**
- * 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 = [
- 'library_id' => [
- 'required',
- Rule::exists('libraries', 'id')->where($this->userCompanyWhere()),
- ],
- 'naming_rule_id' => [
- Rule::when($this->get('naming_rule_id') > 0, [
- Rule::exists('naming_rules', 'id')->whereIn('company_id', [
- 0, Auth::user()->company_id,
- ]),
- ])
- ],
- 'name' => 'required|max:150',
- 'email_subject' => 'max:255',
- 'acl' => [
- new Enum(ContainerACL::class),
- ],
- 'whitelist' => $this->usersCompanyRules(),
- 'mailto' => $this->usersCompanyRules(),
- ];
- $containerRules = $this->customFieldRuleByGroup("container", ['doc_type', 'doc_stage']);
- if ($this->has("naming_rule_id") && $this->get("naming_rule_id") > 0) {
- $this->namingRuleCheck($this->get("naming_rule_id"));
- $namingRules = $this->customFieldRuleByGroup($this->get("naming_rule_id"));
- $rules = [...$rules, ... $namingRules];
- }
- return [...$containerRules, ...$rules];
- }
- }
|