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