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