File manager - Edit - /var/www/html/portalHomolog/app/Http/Requests/Demandas/DemandaTiAbrirRequest.php
Back
<?php namespace App\Http\Requests\Demandas; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Validator; class DemandaTiAbrirRequest extends FormRequest { public function authorize(): bool { return true; } public function rules(): array { return [ 'titulo' => ['required', 'string', 'max:255'], 'descricao' => ['nullable', 'string', 'max:5000'], 'local' => ['required', 'string', 'max:255'], 'setor_id' => ['required', 'exists:setores_ti,id'], 'assunto_id' => ['required', 'exists:assuntos_ti,id'], 'subassunto_id' => ['nullable', 'exists:subassuntos_ti,id'], 'equipamento_id' => ['nullable', 'exists:equipamentos_ti,id'], ]; } public function withValidator(Validator $validator): void { $validator->after(function (Validator $v) { $setorId = $this->input('setor_id'); $assuntoId = $this->input('assunto_id'); $subId = $this->input('subassunto_id'); if ($setorId && $assuntoId) { $pertence = \DB::table('assuntos_ti') ->where('id', $assuntoId) ->where('setor_id', $setorId) ->exists(); if (!$pertence) { $v->errors()->add('assunto_id', 'O assunto selecionado não pertence ao setor informado.'); } } if ($assuntoId && $subId) { $pertence = \DB::table('subassuntos_ti') ->where('id', $subId) ->where('assunto_id', $assuntoId) ->exists(); if (!$pertence) { $v->errors()->add('subassunto_id', 'O subassunto selecionado não pertence ao assunto informado.'); } } }); } public function messages(): array { return [ 'titulo.required' => 'Informe um título para o chamado.', 'titulo.max' => 'O título não pode exceder 255 caracteres.', 'local.required' => 'Informe o local onde fica o setor / equipamento.', 'local.max' => 'O local não pode exceder 255 caracteres.', 'setor_id.required' => 'Selecione o setor.', 'setor_id.exists' => 'Setor inválido.', 'assunto_id.required' => 'Selecione o assunto.', 'assunto_id.exists' => 'Assunto inválido.', 'subassunto_id.exists' => 'Subassunto inválido.', ]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.1 |
proxy
|
phpinfo
|
Settings