48 lines
996 B
PHP
48 lines
996 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use MongoDB\Laravel\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class SalesRoute extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'date',
|
|
'status',
|
|
'total_distance_km',
|
|
'total_duration_minutes',
|
|
'total_visits',
|
|
'started_at',
|
|
'ended_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date' => 'date',
|
|
'total_distance_km' => 'decimal:2',
|
|
'started_at' => 'datetime',
|
|
'ended_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user that owns the route.
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get the waypoints for the route.
|
|
*/
|
|
public function waypoints(): HasMany
|
|
{
|
|
return $this->hasMany(Waypoint::class)->orderBy('recorded_at');
|
|
}
|
|
}
|