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 | 'entity_id' => 'required|integer', |
||
156 | 'entity_type' => 'required|string|max:150', |
||
157 | 'source' => 'required|string|max:150', |
||
158 | 'method' => 'nullable|string|max:150', |
||
159 | 'name_prefix' => 'nullable|string|max:150', |
||
160 | 'first_name' => 'required|string|max:150', |
||
161 | 'middle_name' => 'nullable|string|max:150', |
||
162 | 'last_name' => 'nullable|string|max:150', |
||
163 | 'name_suffix' => 'nullable|string|max:150', |
||
164 | 'job_title' => 'nullable|string|max:150', |
||
165 | 'email' => 'nullable|email|min:3|max:150', |
||
166 | 'phone' => 'nullable|numeric|min:4', |
||
167 | 'fax' => 'nullable|string|max:150', |
||
168 | 'skype' => 'nullable|string|max:150', |
||
169 | 'twitter' => 'nullable|string|max:150', |
||
170 | 'facebook' => 'nullable|string|max:150', |
||
171 | 'google_plus' => 'nullable|string|max:150', |
||
172 | 'linkedin' => 'nullable|string|max:150', |
||
173 | 'country_code' => 'nullable|alpha|size:2|country', |
||
174 | 'language_code' => 'nullable|alpha|size:2|language', |
||
175 | 'birthday' => 'nullable|date_format:Y-m-d', |
||
176 | 'gender' => 'nullable|string|in:m,f', |
||
177 | ]; |
||
178 | |||
179 | /** |
||
180 | * Whether the model should throw a |
||
181 | * ValidationException if it fails validation. |
||
182 | * |
||
183 | * @var bool |
||
184 | */ |
||
185 | protected $throwValidationExceptions = true; |
||
186 | |||
187 | /** |
||
188 | * Create a new Eloquent model instance. |
||
189 | * |
||
190 | * @param array $attributes |
||
191 | */ |
||
192 | public function __construct(array $attributes = []) |
||
198 | |||
199 | /** |
||
200 | * Get the contact name. |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getNameAttribute() |
||
214 | |||
215 | /** |
||
216 | * Get the owner model of the contact. |
||
217 | * |
||
218 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
219 | */ |
||
220 | public function entity(): MorphTo |
||
224 | |||
225 | /** |
||
226 | * Enforce clean sources. |
||
227 | * |
||
228 | * @param string $value |
||
229 | * |
||
230 | * @return void |
||
231 | */ |
||
232 | public function setSourceAttribute($value) |
||
236 | |||
237 | /** |
||
238 | * Enforce clean methods. |
||
239 | * |
||
240 | * @param string $value |
||
241 | * |
||
242 | * @return void |
||
243 | */ |
||
244 | public function setMethodAttribute($value) |
||
248 | |||
249 | /** |
||
250 | * Scope contacts by the given country. |
||
251 | * |
||
252 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
253 | * @param string $countryCode |
||
254 | * |
||
255 | * @return \Illuminate\Database\Eloquent\Builder |
||
256 | */ |
||
257 | public function scopeCountry(Builder $builder, string $countryCode): Builder |
||
261 | |||
262 | /** |
||
263 | * Scope contacts by the given language. |
||
264 | * |
||
265 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
266 | * @param string $languageCode |
||
267 | * |
||
268 | * @return \Illuminate\Database\Eloquent\Builder |
||
269 | */ |
||
270 | public function scopeLanguage(Builder $builder, string $languageCode): Builder |
||
274 | |||
275 | /** |
||
276 | * Scope contacts by the given source. |
||
277 | * |
||
278 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
279 | * @param string $source |
||
280 | * |
||
281 | * @return \Illuminate\Database\Eloquent\Builder |
||
282 | */ |
||
283 | public function scopeSource(Builder $builder, string $source): Builder |
||
287 | |||
288 | /** |
||
289 | * Scope contacts by the given method. |
||
290 | * |
||
291 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
292 | * @param string $method |
||
293 | * |
||
294 | * @return \Illuminate\Database\Eloquent\Builder |
||
295 | */ |
||
296 | public function scopeMethod(Builder $builder, string $method): Builder |
||
300 | |||
301 | /** |
||
302 | * A contact may have multiple related contacts. |
||
303 | * |
||
304 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
305 | */ |
||
306 | public function relatives(): BelongsToMany |
||
311 | |||
312 | /** |
||
313 | * A contact may be related to multiple contacts. |
||
314 | * |
||
315 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
316 | */ |
||
317 | public function backRelatives(): BelongsToMany |
||
322 | } |
||
323 |
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.