This commit is contained in:
69
api/app/Http/Requests/PainelSenha/StatusRequest.php
Normal file
69
api/app/Http/Requests/PainelSenha/StatusRequest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\PainelSenha;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StatusRequest 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\Status')->where(function ($query) {
|
||||
return $query
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'tipo_id' => ['required'],
|
||||
'nome' => ['required', 'min:3', 'max:100']
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
Rule::unique('\App\Models\PainelSenha\Status')->where(function ($query) {
|
||||
return $query
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->status),
|
||||
],
|
||||
'tipo_id' => ['required'],
|
||||
'nome' => ['required', 'min:3', 'max:100']
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'centro_custo_id.unique' => 'Já existe um Status cadastrado com o setor e tipo selecionados.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user