-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProdutoDTO.php
43 lines (33 loc) · 990 Bytes
/
ProdutoDTO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace App\DTO;
use Illuminate\Contracts\Validation\Validator;
class ProdutoDTO extends AbstractDTO implements InterfaceDTO
{
public readonly bool $ativo;
public function __construct(
public readonly string $titulo,
public readonly int $estoque = 0,
public readonly float $preco = 0,
public readonly ?string $foto = null,
bool $situacao = false
){
$this->ativo = $situacao;
$this->validate();
}
public function rules():array{
return [
'titulo' => 'required|string|min:10|max:60'
];
}
public function messages():array{
return [
'titulo' => 'Você precisa definir um título entre 10 e 60 caracteres.'
];
}
public function validator():Validator{
return validator($this->toArray(), $this->rules(), $this->messages());
}
public function validate():array{
return $this->validator()->validate();
}
}