1 | <?php |
||
73 | class Address extends Model implements AddressContract |
||
74 | { |
||
75 | use ValidatingTrait; |
||
76 | use GeoDistanceTrait; |
||
77 | use CacheableEloquent; |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | protected $fillable = [ |
||
83 | 'addressable_id', |
||
84 | 'addressable_type', |
||
85 | 'label', |
||
86 | 'name_prefix', |
||
87 | 'first_name', |
||
88 | 'middle_name', |
||
89 | 'last_name', |
||
90 | 'name_suffix', |
||
91 | 'organization', |
||
92 | 'country_code', |
||
93 | 'street', |
||
94 | 'state', |
||
95 | 'city', |
||
96 | 'postal_code', |
||
97 | 'lat', |
||
98 | 'lng', |
||
99 | 'is_primary', |
||
100 | 'is_billing', |
||
101 | 'is_shipping', |
||
102 | ]; |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | protected $casts = [ |
||
108 | 'addressable_id' => 'integer', |
||
109 | 'addressable_type' => 'string', |
||
110 | 'label' => 'string', |
||
111 | 'name_prefix' => 'string', |
||
112 | 'first_name' => 'string', |
||
113 | 'middle_name' => 'string', |
||
114 | 'last_name' => 'string', |
||
115 | 'name_suffix' => 'string', |
||
116 | 'organization' => 'string', |
||
117 | 'country_code' => 'string', |
||
118 | 'street' => 'string', |
||
119 | 'state' => 'string', |
||
120 | 'city' => 'string', |
||
121 | 'postal_code' => 'string', |
||
122 | 'lat' => 'float', |
||
123 | 'lng' => 'float', |
||
124 | 'is_primary' => 'boolean', |
||
125 | 'is_billing' => 'boolean', |
||
126 | 'is_shipping' => 'boolean', |
||
127 | 'deleted_at' => 'datetime', |
||
128 | ]; |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | protected $observables = [ |
||
134 | 'validating', |
||
135 | 'validated', |
||
136 | ]; |
||
137 | |||
138 | /** |
||
139 | * The default rules that the model will validate against. |
||
140 | * |
||
141 | * @var array |
||
142 | */ |
||
143 | protected $rules = [ |
||
144 | 'addressable_id' => 'required|integer', |
||
145 | 'addressable_type' => 'required|string|max:150', |
||
146 | 'label' => 'nullable|string|max:150', |
||
147 | 'name_prefix' => 'nullable|string|max:150', |
||
148 | 'first_name' => 'nullable|string|max:150', |
||
149 | 'middle_name' => 'nullable|string|max:150', |
||
150 | 'last_name' => 'nullable|string|max:150', |
||
151 | 'name_suffix' => 'nullable|string|max:150', |
||
152 | 'organization' => 'nullable|string|max:150', |
||
153 | 'country_code' => 'nullable|alpha|size:2|country', |
||
154 | 'street' => 'nullable|string|max:150', |
||
155 | 'state' => 'nullable|string|max:150', |
||
156 | 'city' => 'nullable|string|max:150', |
||
157 | 'postal_code' => 'nullable|string|max:150', |
||
158 | 'lat' => 'nullable|numeric', |
||
159 | 'lng' => 'nullable|numeric', |
||
160 | 'is_primary' => 'sometimes|boolean', |
||
161 | 'is_billing' => 'sometimes|boolean', |
||
162 | 'is_shipping' => 'sometimes|boolean', |
||
163 | ]; |
||
164 | |||
165 | /** |
||
166 | * Whether the model should throw a |
||
167 | * ValidationException if it fails validation. |
||
168 | * |
||
169 | * @var bool |
||
170 | */ |
||
171 | protected $throwValidationExceptions = true; |
||
172 | |||
173 | /** |
||
174 | * Create a new Eloquent model instance. |
||
175 | * |
||
176 | * @param array $attributes |
||
177 | */ |
||
178 | public function __construct(array $attributes = []) |
||
184 | |||
185 | /** |
||
186 | * Get the owner model of the address. |
||
187 | * |
||
188 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
189 | */ |
||
190 | public function addressable(): MorphTo |
||
194 | |||
195 | /** |
||
196 | * Scope primary addresses. |
||
197 | * |
||
198 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
199 | * |
||
200 | * @return \Illuminate\Database\Eloquent\Builder |
||
201 | */ |
||
202 | public function scopeIsPrimary(Builder $builder): Builder |
||
206 | |||
207 | /** |
||
208 | * Scope billing addresses. |
||
209 | * |
||
210 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
211 | * |
||
212 | * @return \Illuminate\Database\Eloquent\Builder |
||
213 | */ |
||
214 | public function scopeIsBilling(Builder $builder): Builder |
||
218 | |||
219 | /** |
||
220 | * Scope shipping addresses. |
||
221 | * |
||
222 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
223 | * |
||
224 | * @return \Illuminate\Database\Eloquent\Builder |
||
225 | */ |
||
226 | public function scopeIsShipping(Builder $builder): Builder |
||
230 | |||
231 | /** |
||
232 | * Scope addresses by the given country. |
||
233 | * |
||
234 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
235 | * @param string $countryCode |
||
236 | * |
||
237 | * @return \Illuminate\Database\Eloquent\Builder |
||
238 | */ |
||
239 | public function scopeInCountry(Builder $builder, string $countryCode): Builder |
||
243 | |||
244 | /** |
||
245 | * Scope addresses by the given language. |
||
246 | * |
||
247 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
248 | * @param string $languageCode |
||
249 | * |
||
250 | * @return \Illuminate\Database\Eloquent\Builder |
||
251 | */ |
||
252 | public function scopeInLanguage(Builder $builder, string $languageCode): Builder |
||
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | protected static function boot() |
||
280 | } |
||
281 |
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.