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