1 | <?php |
||
71 | class Contact extends Model |
||
72 | { |
||
73 | use ValidatingTrait; |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | protected $fillable = [ |
||
79 | 'entity_id', |
||
80 | 'entity_type', |
||
81 | 'source', |
||
82 | 'method', |
||
83 | 'given_name', |
||
84 | 'family_name', |
||
85 | 'title', |
||
86 | 'organization', |
||
87 | 'email', |
||
88 | 'phone', |
||
89 | 'fax', |
||
90 | 'country_code', |
||
91 | 'language_code', |
||
92 | 'birthday', |
||
93 | 'gender', |
||
94 | 'national_id_type', |
||
95 | 'national_id', |
||
96 | 'source', |
||
97 | 'method', |
||
98 | 'notes', |
||
99 | ]; |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | protected $casts = [ |
||
105 | 'entity_id' => 'integer', |
||
106 | 'entity_type' => 'string', |
||
107 | 'given_name' => 'string', |
||
108 | 'family_name' => 'string', |
||
109 | 'title' => 'string', |
||
110 | 'organization' => 'string', |
||
111 | 'email' => 'string', |
||
112 | 'phone' => 'string', |
||
113 | 'fax' => 'string', |
||
114 | 'country_code' => 'string', |
||
115 | 'language_code' => 'string', |
||
116 | 'birthday' => 'string', |
||
117 | 'gender' => 'string', |
||
118 | 'national_id_type' => 'string', |
||
119 | 'national_id' => 'string', |
||
120 | 'source' => 'string', |
||
121 | 'method' => 'string', |
||
122 | 'notes' => 'string', |
||
123 | 'deleted_at' => 'datetime', |
||
124 | ]; |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | protected $observables = [ |
||
130 | 'validating', |
||
131 | 'validated', |
||
132 | ]; |
||
133 | |||
134 | /** |
||
135 | * The default rules that the model will validate against. |
||
136 | * |
||
137 | * @var array |
||
138 | */ |
||
139 | protected $rules = [ |
||
140 | 'entity_id' => 'required|integer', |
||
141 | 'entity_type' => 'required|string|strip_tags|max:150', |
||
142 | 'given_name' => 'required|string|strip_tags|max:150', |
||
143 | 'family_name' => 'nullable|string|strip_tags|max:150', |
||
144 | 'title' => 'nullable|string|strip_tags|max:150', |
||
145 | 'organization' => 'nullable|string|strip_tags|max:150', |
||
146 | 'email' => 'required|email|min:3|max:128', |
||
147 | 'phone' => 'nullable|phone:AUTO', |
||
148 | 'fax' => 'nullable|string|strip_tags|max:150', |
||
149 | 'country_code' => 'nullable|alpha|size:2|country', |
||
150 | 'language_code' => 'nullable|alpha|size:2|language', |
||
151 | 'birthday' => 'nullable|date_format:Y-m-d', |
||
152 | 'gender' => 'nullable|in:male,female', |
||
153 | 'national_id_type' => 'nullable|in:identification,passport,other', |
||
154 | 'national_id' => 'nullable|string|strip_tags|max:150', |
||
155 | 'source' => 'nullable|string|strip_tags|max:150', |
||
156 | 'method' => 'nullable|string|strip_tags|max:150', |
||
157 | 'notes' => 'nullable|string|strip_tags|max:32768', |
||
158 | ]; |
||
159 | |||
160 | /** |
||
161 | * Whether the model should throw a |
||
162 | * ValidationException if it fails validation. |
||
163 | * |
||
164 | * @var bool |
||
165 | */ |
||
166 | protected $throwValidationExceptions = true; |
||
167 | |||
168 | /** |
||
169 | * Create a new Eloquent model instance. |
||
170 | * |
||
171 | * @param array $attributes |
||
172 | */ |
||
173 | public function __construct(array $attributes = []) |
||
179 | |||
180 | /** |
||
181 | * Get the owner model of the contact. |
||
182 | * |
||
183 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
184 | */ |
||
185 | public function entity(): MorphTo |
||
189 | |||
190 | /** |
||
191 | * Enforce clean sources. |
||
192 | * |
||
193 | * @param string $value |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | public function setSourceAttribute($value): void |
||
201 | |||
202 | /** |
||
203 | * Enforce clean methods. |
||
204 | * |
||
205 | * @param string $value |
||
206 | * |
||
207 | * @return void |
||
208 | */ |
||
209 | public function setMethodAttribute($value): void |
||
213 | |||
214 | /** |
||
215 | * Scope contacts by the given country. |
||
216 | * |
||
217 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
218 | * @param string $countryCode |
||
219 | * |
||
220 | * @return \Illuminate\Database\Eloquent\Builder |
||
221 | */ |
||
222 | public function scopeCountry(Builder $builder, string $countryCode): Builder |
||
226 | |||
227 | /** |
||
228 | * Scope contacts by the given language. |
||
229 | * |
||
230 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
231 | * @param string $languageCode |
||
232 | * |
||
233 | * @return \Illuminate\Database\Eloquent\Builder |
||
234 | */ |
||
235 | public function scopeLanguage(Builder $builder, string $languageCode): Builder |
||
239 | |||
240 | /** |
||
241 | * Scope contacts by the given source. |
||
242 | * |
||
243 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
244 | * @param string $source |
||
245 | * |
||
246 | * @return \Illuminate\Database\Eloquent\Builder |
||
247 | */ |
||
248 | public function scopeSource(Builder $builder, string $source): Builder |
||
252 | |||
253 | /** |
||
254 | * Scope contacts by the given method. |
||
255 | * |
||
256 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
257 | * @param string $method |
||
258 | * |
||
259 | * @return \Illuminate\Database\Eloquent\Builder |
||
260 | */ |
||
261 | public function scopeMethod(Builder $builder, string $method): Builder |
||
265 | |||
266 | /** |
||
267 | * Get full name attribute. |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | public function getFullNameAttribute(): string |
||
275 | |||
276 | /** |
||
277 | * A contact may have multiple related contacts. |
||
278 | * |
||
279 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
280 | */ |
||
281 | public function relatives(): BelongsToMany |
||
286 | |||
287 | /** |
||
288 | * A contact may be related to multiple contacts. |
||
289 | * |
||
290 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
291 | */ |
||
292 | public function backRelatives(): BelongsToMany |
||
297 | } |
||
298 |