-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.php
31 lines (27 loc) · 890 Bytes
/
Entity.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
<?php
class Entity
{
private $schema = [
'first_name' => 'required|string|min:2|max:30|alphaspace',
'last_name' => 'required|string|min:2|max:30|alphaspace',
'full_name' => 'read_only|from:getFullName',
'dob' => 'required|date|min:01/01/1900|max:now -10 years',
'age' => 'read_only|from:getAge',
'canBuyAlcohol' => 'read_only|from:canBuyAlcohol',
'price' => 'required|price',
'children' => 'array',
'children.*.name' => 'required|string|min:2|max:30|alphaspace'
];
public function getFullName()
{
return $this->get('first_name') . ' ' . $this->get('last_name');
}
public function getAge()
{
return (new DateTime())->format('y') - $this->get('dob')->format('Y');
}
public function canBuyAlcohol()
{
return $this->get('age') >= 18;
}
}