This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ProntoAtendimento\ClassificacaoRisco;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ClassificacaoRiscoRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'max:100',
|
||||
Rule::unique('\App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco')->where(function ($query) {
|
||||
return $query->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::unique('\App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco')->where(function ($query) {
|
||||
return $query->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'max:100',
|
||||
Rule::unique('\App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco')->where(function ($query) {
|
||||
return $query->whereNull('deleted_at');
|
||||
})->ignore($this->classificacao_risco),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::unique('\App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco')->where(function ($query) {
|
||||
return $query->whereNull('deleted_at');
|
||||
})->ignore($this->classificacao_risco),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'tipo_id.unique' => 'Já existe uma classificação de risco com este tipo.',
|
||||
'nome.unique' => 'Já existe uma classificação de risco com este nome.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user