This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class LoteamentoRequest 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 [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
'unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
"unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,{$this->loteamento},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Loteamento já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user