This commit is contained in:
67
api/app/Http/Requests/PainelSenha/OpcaoChamadaRequest.php
Normal file
67
api/app/Http/Requests/PainelSenha/OpcaoChamadaRequest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\PainelSenha;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class OpcaoChamadaRequest 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('painel_senha_opcao_chamada')->where(function ($query) {
|
||||
return $query->where('tela_id', $this->tela_id)->whereNull('deleted_at');
|
||||
})
|
||||
],
|
||||
'tela_id' => [
|
||||
'required',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
Rule::unique('painel_senha_opcao_chamada')->where(function ($query) {
|
||||
return $query->where('tela_id', $this->tela_id)->whereNull('deleted_at');
|
||||
})->ignore($this->opcao_chamada),
|
||||
],
|
||||
'tela_id' => [
|
||||
'required',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id.unique' => 'Já existe uma opção de chamada cadastrada com estas informações.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user