1 | <?php |
||
67 | class Address extends Model |
||
68 | { |
||
69 | use ValidatingTrait; |
||
70 | use GeoDistanceTrait; |
||
71 | use CacheableEloquent; |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | protected $fillable = [ |
||
77 | 'addressable_id', |
||
78 | 'addressable_type', |
||
79 | 'label', |
||
80 | 'given_name', |
||
81 | 'family_name', |
||
82 | 'organization', |
||
83 | 'country_code', |
||
84 | 'street', |
||
85 | 'state', |
||
86 | 'city', |
||
87 | 'postal_code', |
||
88 | 'latitude', |
||
89 | 'longitude', |
||
90 | 'is_primary', |
||
91 | 'is_billing', |
||
92 | 'is_shipping', |
||
93 | ]; |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | protected $casts = [ |
||
99 | 'addressable_id' => 'integer', |
||
100 | 'addressable_type' => 'string', |
||
101 | 'label' => 'string', |
||
102 | 'given_name' => 'string', |
||
103 | 'family_name' => 'string', |
||
104 | 'organization' => 'string', |
||
105 | 'country_code' => 'string', |
||
106 | 'street' => 'string', |
||
107 | 'state' => 'string', |
||
108 | 'city' => 'string', |
||
109 | 'postal_code' => 'string', |
||
110 | 'latitude' => 'float', |
||
111 | 'longitude' => 'float', |
||
112 | 'is_primary' => 'boolean', |
||
113 | 'is_billing' => 'boolean', |
||
114 | 'is_shipping' => 'boolean', |
||
115 | 'deleted_at' => 'datetime', |
||
116 | ]; |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | protected $observables = [ |
||
122 | 'validating', |
||
123 | 'validated', |
||
124 | ]; |
||
125 | |||
126 | /** |
||
127 | * The default rules that the model will validate against. |
||
128 | * |
||
129 | * @var array |
||
130 | */ |
||
131 | protected $rules = [ |
||
132 | 'addressable_id' => 'required|integer', |
||
133 | 'addressable_type' => 'required|string|max:150', |
||
134 | 'label' => 'nullable|string|max:150', |
||
135 | 'given_name' => 'required|string|max:150', |
||
136 | 'family_name' => 'nullable|string|max:150', |
||
137 | 'organization' => 'nullable|string|max:150', |
||
138 | 'country_code' => 'nullable|alpha|size:2|country', |
||
139 | 'street' => 'nullable|string|max:150', |
||
140 | 'state' => 'nullable|string|max:150', |
||
141 | 'city' => 'nullable|string|max:150', |
||
142 | 'postal_code' => 'nullable|string|max:150', |
||
143 | 'latitude' => 'nullable|numeric', |
||
144 | 'longitude' => 'nullable|numeric', |
||
145 | 'is_primary' => 'sometimes|boolean', |
||
146 | 'is_billing' => 'sometimes|boolean', |
||
147 | 'is_shipping' => 'sometimes|boolean', |
||
148 | ]; |
||
149 | |||
150 | /** |
||
151 | * Whether the model should throw a |
||
152 | * ValidationException if it fails validation. |
||
153 | * |
||
154 | * @var bool |
||
155 | */ |
||
156 | protected $throwValidationExceptions = true; |
||
157 | |||
158 | /** |
||
159 | * Create a new Eloquent model instance. |
||
160 | * |
||
161 | * @param array $attributes |
||
162 | */ |
||
163 | public function __construct(array $attributes = []) |
||
169 | |||
170 | /** |
||
171 | * Get the owner model of the address. |
||
172 | * |
||
173 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
174 | */ |
||
175 | public function addressable(): MorphTo |
||
179 | |||
180 | /** |
||
181 | * Scope primary addresses. |
||
182 | * |
||
183 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
184 | * |
||
185 | * @return \Illuminate\Database\Eloquent\Builder |
||
186 | */ |
||
187 | public function scopeIsPrimary(Builder $builder): Builder |
||
191 | |||
192 | /** |
||
193 | * Scope billing addresses. |
||
194 | * |
||
195 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
196 | * |
||
197 | * @return \Illuminate\Database\Eloquent\Builder |
||
198 | */ |
||
199 | public function scopeIsBilling(Builder $builder): Builder |
||
203 | |||
204 | /** |
||
205 | * Scope shipping addresses. |
||
206 | * |
||
207 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
208 | * |
||
209 | * @return \Illuminate\Database\Eloquent\Builder |
||
210 | */ |
||
211 | public function scopeIsShipping(Builder $builder): Builder |
||
215 | |||
216 | /** |
||
217 | * Scope addresses by the given country. |
||
218 | * |
||
219 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
220 | * @param string $countryCode |
||
221 | * |
||
222 | * @return \Illuminate\Database\Eloquent\Builder |
||
223 | */ |
||
224 | public function scopeInCountry(Builder $builder, string $countryCode): Builder |
||
228 | |||
229 | /** |
||
230 | * Scope addresses by the given language. |
||
231 | * |
||
232 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
233 | * @param string $languageCode |
||
234 | * |
||
235 | * @return \Illuminate\Database\Eloquent\Builder |
||
236 | */ |
||
237 | public function scopeInLanguage(Builder $builder, string $languageCode): Builder |
||
241 | |||
242 | /** |
||
243 | * Get full name attribute. |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getFullNameAttribute(): string |
||
251 | |||
252 | /** |
||
253 | * {@inheritdoc} |
||
254 | */ |
||
255 | protected static function boot() |
||
275 | } |
||
276 |
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.