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\Services\Validation\Rules\SkillDeclarationBelongsToUserRule; |
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
|
|
|
* Construct a new UpdateReferenceValidator |
24
|
|
|
*/ |
25
|
2 |
|
public function __construct() |
26
|
|
|
{ |
27
|
2 |
|
$this->relationshipIds = Relationship::all()->pluck('id')->toArray(); |
28
|
2 |
|
} |
29
|
|
|
/** |
30
|
|
|
* Get the validation rules that apply to the request. |
31
|
|
|
* |
32
|
|
|
* @return mixed[] |
33
|
|
|
*/ |
34
|
2 |
|
public function rules() : array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
2 |
|
'name' => 'required|string|max:191', |
38
|
|
|
'email' => [ |
39
|
|
|
'required', |
40
|
|
|
'string', |
41
|
|
|
'max:191', |
42
|
|
|
'email', |
43
|
|
|
], |
44
|
|
|
'relationship_id' => [ |
45
|
2 |
|
'required', |
46
|
2 |
|
Rule::in($this->relationshipIds) |
47
|
|
|
], |
48
|
2 |
|
'description' => 'required|string', |
49
|
|
|
|
50
|
|
|
'relatives.skills.*.id' => [ |
51
|
2 |
|
'required', |
52
|
2 |
|
new SkillDeclarationBelongsToUserRule |
53
|
|
|
], |
54
|
|
|
|
55
|
2 |
|
'projects.*.name' => 'required|string|max:191', |
56
|
2 |
|
'projects.*.start_date' => 'required|date', |
57
|
2 |
|
'projects.*.end_date' => 'required|date', |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns a validator made with this data |
65
|
|
|
* |
66
|
|
|
* @param mixed[] $data Data to validate. |
67
|
|
|
* @return Validator |
68
|
|
|
*/ |
69
|
2 |
|
public function validator(array $data) : \Illuminate\Validation\Validator |
70
|
|
|
{ |
71
|
2 |
|
return Validator::make($data, $this->rules()); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|