ldc-wenn-dann-mit-respekt/app/Models/Store.php
Noah Lancien 222347d890 phpstan
2024-01-29 16:20:14 +01:00

96 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property integer $type_id
* @property integer $region_id
* @property string $state
* @property string $street
* @property string $zipcode
* @property string $city
* @property float $latitude
* @property float $longitude
* @property integer $order
* @property string $created_at
* @property string $updated_at
*/
class Store extends Model
{
use HasFactory;
/**
* @var array<string>
*/
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<string, string>
*/
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');
}
}