88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Traits\Models\HasUuidV7AsPrimaryKey;
|
||
|
|
use DateTimeInterface;
|
||
|
|
use Domain\Enums\RepeatFrequency;
|
||
|
|
use Domain\Models\ValueObjects\Entities\PickupExceptionId;
|
||
|
|
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 Ramsey\Uuid\Uuid;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @property string $id
|
||
|
|
* @property \Illuminate\Support\Carbon $date
|
||
|
|
* @property string $label
|
||
|
|
* @property bool $repeatable
|
||
|
|
* @property RepeatFrequency $repeat_frequency Enum Domain\Enums\RepeatFrequency
|
||
|
|
* @property bool $auto_updated
|
||
|
|
* @property \Carbon\CarbonInterface|null $created_at
|
||
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||
|
|
* @property-read \App\Models\ShopPickupExceptionPivot|null $pivot
|
||
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Shop> $shops
|
||
|
|
*
|
||
|
|
* @method static \Database\Factories\PickupExceptionFactory factory($count = null, $state = [])
|
||
|
|
*
|
||
|
|
* @mixin \Eloquent
|
||
|
|
*/
|
||
|
|
#[Fillable([
|
||
|
|
'date',
|
||
|
|
'label',
|
||
|
|
'repeatable',
|
||
|
|
'repeat_frequency',
|
||
|
|
])]
|
||
|
|
#[Guarded([
|
||
|
|
'auto_updated',
|
||
|
|
])]
|
||
|
|
class PickupException extends Model
|
||
|
|
{
|
||
|
|
/** @use HasFactory<\Database\Factories\PickupExceptionFactory> */
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
use HasUuidV7AsPrimaryKey;
|
||
|
|
|
||
|
|
public function getId(): PickupExceptionId
|
||
|
|
{
|
||
|
|
return new PickupExceptionId(Uuid::fromString($this->id));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setAsManuallySaved(): void
|
||
|
|
{
|
||
|
|
$this->setAttribute('auto_updated', false);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Format a date
|
||
|
|
*/
|
||
|
|
#[\Override]
|
||
|
|
protected function serializeDate(DateTimeInterface $date): string
|
||
|
|
{
|
||
|
|
return $date->format('Y-m-d');
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\Shop,$this,\App\Models\ShopPickupExceptionPivot> */
|
||
|
|
public function shops(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Shop::class, 'shop_pickup_exception')
|
||
|
|
->using(ShopPickupExceptionPivot::class)
|
||
|
|
->withPivot(['replacement_date', 'order_deadline_at']);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
protected function casts(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'date' => 'date',
|
||
|
|
'repeatable' => 'bool',
|
||
|
|
'auto_updated' => 'bool',
|
||
|
|
'repeat_frequency' => RepeatFrequency::class,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|