1 | <?php |
||
79 | class Contact extends Model implements ContactContract |
||
80 | { |
||
81 | use ValidatingTrait; |
||
82 | use CacheableEloquent; |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | protected $fillable = [ |
||
88 | 'entity_id', |
||
89 | 'entity_type', |
||
90 | 'source', |
||
91 | 'method', |
||
92 | 'name_prefix', |
||
93 | 'first_name', |
||
94 | 'middle_name', |
||
95 | 'last_name', |
||
96 | 'name_suffix', |
||
97 | 'job_title', |
||
98 | 'email', |
||
99 | 'phone', |
||
100 | 'fax', |
||
101 | 'skype', |
||
102 | 'twitter', |
||
103 | 'facebook', |
||
104 | 'google_plus', |
||
105 | 'linkedin', |
||
106 | 'country_code', |
||
107 | 'language_code', |
||
108 | 'birthday', |
||
109 | 'gender', |
||
110 | ]; |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | protected $casts = [ |
||
116 | 'entity_id' => 'integer', |
||
117 | 'entity_type' => 'string', |
||
118 | 'source' => 'string', |
||
119 | 'method' => 'string', |
||
120 | 'name_prefix' => 'string', |
||
121 | 'first_name' => 'string', |
||
122 | 'middle_name' => 'string', |
||
123 | 'last_name' => 'string', |
||
124 | 'name_suffix' => 'string', |
||
125 | 'job_title' => 'string', |
||
126 | 'email' => 'string', |
||
127 | 'phone' => 'string', |
||
128 | 'fax' => 'string', |
||
129 | 'skype' => 'string', |
||
130 | 'twitter' => 'string', |
||
131 | 'facebook' => 'string', |
||
132 | 'google_plus' => 'string', |
||
133 | 'linkedin' => 'string', |
||
134 | 'country_code' => 'string', |
||
135 | 'language_code' => 'string', |
||
136 | 'birthday' => 'string', |
||
137 | 'gender' => 'string', |
||
138 | 'deleted_at' => 'datetime', |
||
139 | ]; |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | protected $observables = [ |
||
145 | 'validating', |
||
146 | 'validated', |
||
147 | ]; |
||
148 | |||
149 | /** |
||
150 | * The default rules that the model will validate against. |
||
151 | * |
||
152 | * @var array |
||
153 | */ |
||
154 | protected $rules = []; |
||
155 | |||
156 | /** |
||
157 | * Whether the model should throw a |
||
158 | * ValidationException if it fails validation. |
||
159 | * |
||
160 | * @var bool |
||
161 | */ |
||
162 | protected $throwValidationExceptions = true; |
||
163 | |||
164 | /** |
||
165 | * Create a new Eloquent model instance. |
||
166 | * |
||
167 | * @param array $attributes |
||
168 | */ |
||
169 | public function __construct(array $attributes = []) |
||
199 | |||
200 | /** |
||
201 | * Get the contact name. |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getNameAttribute() |
||
215 | |||
216 | /** |
||
217 | * Get the owner model of the contact. |
||
218 | * |
||
219 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
220 | */ |
||
221 | public function entity(): MorphTo |
||
225 | |||
226 | /** |
||
227 | * Enforce clean sources. |
||
228 | * |
||
229 | * @param string $value |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | public function setSourceAttribute($value) |
||
237 | |||
238 | /** |
||
239 | * Enforce clean methods. |
||
240 | * |
||
241 | * @param string $value |
||
242 | * |
||
243 | * @return void |
||
244 | */ |
||
245 | public function setMethodAttribute($value) |
||
249 | |||
250 | /** |
||
251 | * Scope contacts by the given country. |
||
252 | * |
||
253 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
254 | * @param string $countryCode |
||
255 | * |
||
256 | * @return \Illuminate\Database\Eloquent\Builder |
||
257 | */ |
||
258 | public function scopeCountry(Builder $builder, string $countryCode): Builder |
||
262 | |||
263 | /** |
||
264 | * Scope contacts by the given language. |
||
265 | * |
||
266 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
267 | * @param string $languageCode |
||
268 | * |
||
269 | * @return \Illuminate\Database\Eloquent\Builder |
||
270 | */ |
||
271 | public function scopeLanguage(Builder $builder, string $languageCode): Builder |
||
275 | |||
276 | /** |
||
277 | * Scope contacts by the given source. |
||
278 | * |
||
279 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
280 | * @param string $source |
||
281 | * |
||
282 | * @return \Illuminate\Database\Eloquent\Builder |
||
283 | */ |
||
284 | public function scopeSource(Builder $builder, string $source): Builder |
||
288 | |||
289 | /** |
||
290 | * Scope contacts by the given method. |
||
291 | * |
||
292 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
293 | * @param string $method |
||
294 | * |
||
295 | * @return \Illuminate\Database\Eloquent\Builder |
||
296 | */ |
||
297 | public function scopeMethod(Builder $builder, string $method): Builder |
||
301 | |||
302 | /** |
||
303 | * A contact may have multiple related contacts. |
||
304 | * |
||
305 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
306 | */ |
||
307 | public function relatives(): BelongsToMany |
||
312 | |||
313 | /** |
||
314 | * A contact may be related to multiple contacts. |
||
315 | * |
||
316 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
317 | */ |
||
318 | public function backRelatives(): BelongsToMany |
||
323 | } |
||
324 |
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.