*/ protected $fillable = [ 'type_id', 'region_id', 'state', 'street', 'zipcode', 'city', 'latitude', 'longitude', 'order', 'created_at', 'updated_at' ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'latitude' => 'float', 'longitude' => 'float' ]; // * EVENTS /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::creating(function (self $model) { self::setOrder($model); }); } // * METHODS /** * Set order after the last element of the list. * * @param self $model * @return void */ private static function setOrder(self $model): void { $model->order = \intval(self::query()->max('order')) + 1; } // * RELATIONSHIPS /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function storeType() { return $this->belongsTo(StoreType::class, 'type_id'); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function storeRegion() { return $this->belongsTo(StoreRegion::class, 'region_id'); } }