36 lines
729 B
PHP
36 lines
729 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Trip extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'name',
|
|
'description',
|
|
];
|
|
|
|
/**
|
|
* Get the user that owns this trip
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get all cities in this trip
|
|
*/
|
|
public function cities(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(City::class, 'city_trip')
|
|
->withPivot('order')
|
|
->withTimestamps()
|
|
->orderByPivot('order');
|
|
}
|
|
}
|