This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SetorRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'POST':
|
||||
return $this->getPostRules();
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->setor),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Um Setor com o mesmo Serviço e Nome já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user