64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?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.'
|
|
];
|
|
}
|
|
}
|