82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Models\HasUuidV7AsPrimaryKey;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
/**
|
|
* @property string $id
|
|
* @property string $name
|
|
* @property string $address
|
|
* @property string $postcode
|
|
* @property string $city
|
|
* @property string|null $phone
|
|
* @property string|null $latitude
|
|
* @property string|null $longitude
|
|
* @property bool $default
|
|
* @property \Carbon\CarbonInterface|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Order> $orders
|
|
* @property-read \App\Models\ShopPickupExceptionPivot|null $pivot
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PickupException> $pickupExceptions
|
|
*
|
|
* @method static \Database\Factories\ShopFactory factory($count = null, $state = [])
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
#[Fillable([
|
|
'name',
|
|
'address',
|
|
'postcode',
|
|
'city',
|
|
'phone',
|
|
'latitude',
|
|
'longitude',
|
|
])]
|
|
#[Guarded([
|
|
'default',
|
|
])]
|
|
class Shop extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\ShopFactory> */
|
|
use HasFactory;
|
|
|
|
use HasUuidV7AsPrimaryKey;
|
|
|
|
public function getId(): ShopId
|
|
{
|
|
return new ShopId(Uuid::fromString($this->id));
|
|
}
|
|
|
|
/** @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\PickupException,$this,\App\Models\ShopPickupExceptionPivot> */
|
|
public function pickupExceptions(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(PickupException::class, 'shop_pickup_exception')
|
|
->using(ShopPickupExceptionPivot::class)
|
|
->withPivot(['replacement_date', 'order_deadline_at']);
|
|
}
|
|
|
|
/** @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\Order,$this> */
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->hasMany(Order::class);
|
|
}
|
|
|
|
#[\Override]
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'default' => 'bool',
|
|
];
|
|
}
|
|
}
|