This commit is contained in:
99
api/app/Http/Requests/PainelSenha/OpcaoEntradaRequest.php
Normal file
99
api/app/Http/Requests/PainelSenha/OpcaoEntradaRequest.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\PainelSenha;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class OpcaoEntradaRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'POST':
|
||||
return $this->getPostRules();
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
break;
|
||||
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
Rule::unique('\App\Models\PainelSenha\OpcaoEntrada')->where(function ($query) {
|
||||
return $query
|
||||
->where('nome', $this->nome)
|
||||
->where('sigla', $this->sigla)
|
||||
->where('modulo_id', $this->modulo_id)
|
||||
->where('faixa_etaria_id', $this->faixa_etaria_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'modulo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'nome' => [
|
||||
'required',
|
||||
'min:3',
|
||||
'max:100',
|
||||
],
|
||||
'sigla' => [
|
||||
'required',
|
||||
'min:2',
|
||||
'max:2',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
Rule::unique('\App\Models\PainelSenha\OpcaoEntrada')->where(function ($query) {
|
||||
return $query
|
||||
->where('nome', $this->nome)
|
||||
->where('sigla', $this->sigla)
|
||||
->where('modulo_id', $this->modulo_id)
|
||||
->where('faixa_etaria_id', $this->faixa_etaria_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->opcao_entrada),
|
||||
],
|
||||
'modulo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'nome' => [
|
||||
'required',
|
||||
'min:3',
|
||||
'max:100',
|
||||
],
|
||||
'sigla' => [
|
||||
'required',
|
||||
'min:2',
|
||||
'max:2',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id.unique' => 'Já existe uma opção de entrada cadastrada com estas informações.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user