62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Ride extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'pickup_label',
|
|
'pickup_lat',
|
|
'pickup_lng',
|
|
'destination_label',
|
|
'destination_lat',
|
|
'destination_lng',
|
|
'scheduled_for',
|
|
'status',
|
|
'eta_minutes',
|
|
'source_channel',
|
|
'context_zone',
|
|
'locale',
|
|
];
|
|
|
|
protected $casts = [
|
|
'pickup_lat' => 'decimal:7',
|
|
'pickup_lng' => 'decimal:7',
|
|
'destination_lat' => 'decimal:7',
|
|
'destination_lng' => 'decimal:7',
|
|
'scheduled_for' => 'datetime',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (Ride $ride) {
|
|
if (blank($ride->uuid)) {
|
|
$ride->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function recommendations(): HasMany
|
|
{
|
|
return $this->hasMany(RideRecommendation::class)->orderBy('position');
|
|
}
|
|
|
|
public function bookings(): HasMany
|
|
{
|
|
return $this->hasMany(Booking::class);
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
}
|