56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Event\Models;
|
|
|
|
use App\Domains\Catalog\Models\Variant;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
#[Fillable([
|
|
'tenant_code',
|
|
'date',
|
|
'time_start',
|
|
'time_end',
|
|
])]
|
|
class EventDate extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public $timestamps = false;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date' => 'date:Y-m-d',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<Tenant, $this> */
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
|
}
|
|
|
|
/** @return HasMany<Variant, $this> */
|
|
public function variants(): HasMany
|
|
{
|
|
return $this->hasMany(Variant::class);
|
|
}
|
|
|
|
public function startsAt(): CarbonInterface
|
|
{
|
|
return Carbon::parse($this->date->format('Y-m-d').' '.$this->time_start);
|
|
}
|
|
|
|
public function endsAt(): CarbonInterface
|
|
{
|
|
return Carbon::parse($this->date->format('Y-m-d').' '.$this->time_end);
|
|
}
|
|
}
|