62 lines
1.2 KiB
PHP
62 lines
1.2 KiB
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\HasMany;
|
|
|
|
class Driver extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'driver_id',
|
|
'name',
|
|
'license_number',
|
|
'license_type',
|
|
'license_expiry_date',
|
|
'phone',
|
|
'email',
|
|
'assigned_vehicle',
|
|
'vehicle_plate',
|
|
'performance_score',
|
|
'status',
|
|
'attributes',
|
|
'notes',
|
|
'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'attributes' => 'array',
|
|
'is_active' => 'boolean',
|
|
'license_expiry_date' => 'date',
|
|
];
|
|
|
|
/**
|
|
* Get the user associated with this driver
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get devices assigned to this driver
|
|
*/
|
|
public function devices(): HasMany
|
|
{
|
|
return $this->hasMany(Device::class);
|
|
}
|
|
|
|
/**
|
|
* Scope for active drivers
|
|
*/
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
}
|