45 lines
957 B
PHP
45 lines
957 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||
|
|
|
||
|
|
class PlannableItem extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'trip_id',
|
||
|
|
'name',
|
||
|
|
'type',
|
||
|
|
'address',
|
||
|
|
'notes',
|
||
|
|
'metadata',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'metadata' => 'array',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function trip(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Trip::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function calendarSlots(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(CalendarSlot::class, 'planned_items')
|
||
|
|
->withPivot('sort_order')
|
||
|
|
->withTimestamps()
|
||
|
|
->orderBy('planned_items.sort_order');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function plannedItems()
|
||
|
|
{
|
||
|
|
return $this->hasMany(PlannedItem::class);
|
||
|
|
}
|
||
|
|
}
|