1 | <?php |
||
78 | class Contact extends Model |
||
79 | { |
||
80 | use ValidatingTrait; |
||
81 | use CacheableEloquent; |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | protected $fillable = [ |
||
87 | 'entity_id', |
||
88 | 'entity_type', |
||
89 | 'source', |
||
90 | 'method', |
||
91 | 'name_prefix', |
||
92 | 'first_name', |
||
93 | 'middle_name', |
||
94 | 'last_name', |
||
95 | 'name_suffix', |
||
96 | 'title', |
||
97 | 'email', |
||
98 | 'phone', |
||
99 | 'fax', |
||
100 | 'skype', |
||
101 | 'twitter', |
||
102 | 'facebook', |
||
103 | 'google_plus', |
||
104 | 'linkedin', |
||
105 | 'country_code', |
||
106 | 'language_code', |
||
107 | 'birthday', |
||
108 | 'gender', |
||
109 | ]; |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | protected $casts = [ |
||
115 | 'entity_id' => 'integer', |
||
116 | 'entity_type' => 'string', |
||
117 | 'source' => 'string', |
||
118 | 'method' => 'string', |
||
119 | 'name_prefix' => 'string', |
||
120 | 'first_name' => 'string', |
||
121 | 'middle_name' => 'string', |
||
122 | 'last_name' => 'string', |
||
123 | 'name_suffix' => 'string', |
||
124 | 'title' => 'string', |
||
125 | 'email' => 'string', |
||
126 | 'phone' => 'string', |
||
127 | 'fax' => 'string', |
||
128 | 'skype' => 'string', |
||
129 | 'twitter' => 'string', |
||
130 | 'facebook' => 'string', |
||
131 | 'google_plus' => 'string', |
||
132 | 'linkedin' => 'string', |
||
133 | 'country_code' => 'string', |
||
134 | 'language_code' => 'string', |
||
135 | 'birthday' => 'string', |
||
136 | 'gender' => 'string', |
||
137 | 'deleted_at' => 'datetime', |
||
138 | ]; |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | protected $observables = [ |
||
144 | 'validating', |
||
145 | 'validated', |
||
146 | ]; |
||
147 | |||
148 | /** |
||
149 | * The default rules that the model will validate against. |
||
150 | * |
||
151 | * @var array |
||
152 | */ |
||
153 | protected $rules = [ |
||
154 | 'entity_id' => 'required|integer', |
||
155 | 'entity_type' => 'required|string|max:150', |
||
156 | 'source' => 'required|string|max:150', |
||
157 | 'method' => 'nullable|string|max:150', |
||
158 | 'name_prefix' => 'nullable|string|max:150', |
||
159 | 'first_name' => 'required|string|max:150', |
||
160 | 'middle_name' => 'nullable|string|max:150', |
||
161 | 'last_name' => 'nullable|string|max:150', |
||
162 | 'name_suffix' => 'nullable|string|max:150', |
||
163 | 'title' => 'nullable|string|max:150', |
||
164 | 'email' => 'nullable|email|min:3|max:150', |
||
165 | 'phone' => 'nullable|numeric|min:4', |
||
166 | 'fax' => 'nullable|string|max:150', |
||
167 | 'skype' => 'nullable|string|max:150', |
||
168 | 'twitter' => 'nullable|string|max:150', |
||
169 | 'facebook' => 'nullable|string|max:150', |
||
170 | 'google_plus' => 'nullable|string|max:150', |
||
171 | 'linkedin' => 'nullable|string|max:150', |
||
172 | 'country_code' => 'nullable|alpha|size:2|country', |
||
173 | 'language_code' => 'nullable|alpha|size:2|language', |
||
174 | 'birthday' => 'nullable|date_format:Y-m-d', |
||
175 | 'gender' => 'nullable|string|in:male,female', |
||
176 | ]; |
||
177 | |||
178 | /** |
||
179 | * Whether the model should throw a |
||
180 | * ValidationException if it fails validation. |
||
181 | * |
||
182 | * @var bool |
||
183 | */ |
||
184 | protected $throwValidationExceptions = true; |
||
185 | |||
186 | /** |
||
187 | * Create a new Eloquent model instance. |
||
188 | * |
||
189 | * @param array $attributes |
||
190 | */ |
||
191 | public function __construct(array $attributes = []) |
||
197 | |||
198 | /** |
||
199 | * Get the contact name. |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getNameAttribute(): string |
||
213 | |||
214 | /** |
||
215 | * Get the owner model of the contact. |
||
216 | * |
||
217 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
218 | */ |
||
219 | public function entity(): MorphTo |
||
223 | |||
224 | /** |
||
225 | * Enforce clean sources. |
||
226 | * |
||
227 | * @param string $value |
||
228 | * |
||
229 | * @return void |
||
230 | */ |
||
231 | public function setSourceAttribute($value): void |
||
235 | |||
236 | /** |
||
237 | * Enforce clean methods. |
||
238 | * |
||
239 | * @param string $value |
||
240 | * |
||
241 | * @return void |
||
242 | */ |
||
243 | public function setMethodAttribute($value): void |
||
247 | |||
248 | /** |
||
249 | * Scope contacts by the given country. |
||
250 | * |
||
251 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
252 | * @param string $countryCode |
||
253 | * |
||
254 | * @return \Illuminate\Database\Eloquent\Builder |
||
255 | */ |
||
256 | public function scopeCountry(Builder $builder, string $countryCode): Builder |
||
260 | |||
261 | /** |
||
262 | * Scope contacts by the given language. |
||
263 | * |
||
264 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
265 | * @param string $languageCode |
||
266 | * |
||
267 | * @return \Illuminate\Database\Eloquent\Builder |
||
268 | */ |
||
269 | public function scopeLanguage(Builder $builder, string $languageCode): Builder |
||
273 | |||
274 | /** |
||
275 | * Scope contacts by the given source. |
||
276 | * |
||
277 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
278 | * @param string $source |
||
279 | * |
||
280 | * @return \Illuminate\Database\Eloquent\Builder |
||
281 | */ |
||
282 | public function scopeSource(Builder $builder, string $source): Builder |
||
286 | |||
287 | /** |
||
288 | * Scope contacts by the given method. |
||
289 | * |
||
290 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
291 | * @param string $method |
||
292 | * |
||
293 | * @return \Illuminate\Database\Eloquent\Builder |
||
294 | */ |
||
295 | public function scopeMethod(Builder $builder, string $method): Builder |
||
299 | |||
300 | /** |
||
301 | * A contact may have multiple related contacts. |
||
302 | * |
||
303 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
304 | */ |
||
305 | public function relatives(): BelongsToMany |
||
310 | |||
311 | /** |
||
312 | * A contact may be related to multiple contacts. |
||
313 | * |
||
314 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
315 | */ |
||
316 | public function backRelatives(): BelongsToMany |
||
321 | } |
||
322 |
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.