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