|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Services\Validation\Requests; |
|
4
|
|
|
|
|
5
|
|
|
use App\Services\Validation\BaseDataValidator; |
|
6
|
|
|
use App\Services\Validation\Contracts\DataValidator; |
|
7
|
|
|
use Illuminate\Support\Facades\Validator; |
|
8
|
|
|
use Illuminate\Validation\Rule; |
|
9
|
|
|
use App\Models\Lookup\Relationship; |
|
10
|
|
|
use App\Models\Skill; |
|
11
|
|
|
|
|
12
|
|
|
class UpdateReferenceValidator extends BaseDataValidator implements DataValidator |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Array of all possible relationship ids. |
|
17
|
|
|
* |
|
18
|
|
|
* @var int[] |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $relationshipIds; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Array of all possible skill ids. |
|
24
|
|
|
* |
|
25
|
|
|
* @var int[] |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $skillIds; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Construct a new UpdateReferenceValidator |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->relationshipIds = Relationship::all()->pluck('id')->toArray(); |
|
35
|
|
|
$this->skillIds = Skill::all()->pluck('id')->toArray(); |
|
36
|
|
|
} |
|
37
|
|
|
/** |
|
38
|
|
|
* Get the validation rules that apply to the request. |
|
39
|
|
|
* |
|
40
|
|
|
* @return mixed[] |
|
41
|
|
|
*/ |
|
42
|
|
|
public function rules() : array |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
'name' => 'required|string|max:191', |
|
46
|
|
|
'email' => [ |
|
47
|
|
|
'required', |
|
48
|
|
|
'string', |
|
49
|
|
|
'max:191', |
|
50
|
|
|
'email', |
|
51
|
|
|
], |
|
52
|
|
|
'relationship_id' => [ |
|
53
|
|
|
'required', |
|
54
|
|
|
Rule::in($this->relationshipIds) |
|
55
|
|
|
], |
|
56
|
|
|
'description' => 'required|string', |
|
57
|
|
|
|
|
58
|
|
|
'relatives.skills.*.id' => [ |
|
59
|
|
|
'required', |
|
60
|
|
|
Rule::in($this->skillIds) |
|
61
|
|
|
], |
|
62
|
|
|
|
|
63
|
|
|
'projects.*.name' => 'required|string|max:191', |
|
64
|
|
|
'projects.*.start_date' => 'required|date', |
|
65
|
|
|
'projects.*.end_date' => 'required|date', |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns a validator made with this data |
|
73
|
|
|
* |
|
74
|
|
|
* @param mixed[] $data Data to validate. |
|
75
|
|
|
* @return Validator |
|
|
|
|
|
|
76
|
|
|
*/ |
|
77
|
|
|
public function validator(array $data) : \Illuminate\Validation\Validator |
|
78
|
|
|
{ |
|
79
|
|
|
return Validator::make($data, $this->rules()); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|