This commit is contained in:
75
api/app/Http/Requests/PainelSenha/TelaRequest.php
Normal file
75
api/app/Http/Requests/PainelSenha/TelaRequest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\PainelSenha;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TelaRequest 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 [
|
||||
'infraestrutura_id' => [
|
||||
'required',
|
||||
Rule::unique('painel_senha_tela')->where(function ($query) {
|
||||
return $query
|
||||
->where('nome', $this->nome)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
],
|
||||
'nome' => [
|
||||
'required',
|
||||
'min:3',
|
||||
'max:100',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'infraestrutura_id' => [
|
||||
'required',
|
||||
Rule::unique('painel_senha_tela')->where(function ($query) {
|
||||
return $query
|
||||
->where('nome', $this->nome)
|
||||
->where('id', '!=', $this->tela)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
],
|
||||
'nome' => [
|
||||
'required',
|
||||
'max:100',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'infraestrutura_id.unique' => 'Já existe uma tela cadastrada com estas informações.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user