File: /var/www/html/dashboard.orbiwheels.com/app/Models/Vehicle.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Vehicle extends Model
{
use SoftDeletes;
protected $fillable = [
'name',
'vehicle_type_id',
'transporter_id',
'driver_id',
'status',
'registration_number',
'make',
'model',
'year',
'capacity_kg',
'has_gps',
'deleted_at',
];
public function vehicleType()
{
return $this->belongsTo(VehicleType::class);
}
public function transporter()
{
return $this->belongsTo(Transporter::class);
}
public function documents()
{
return $this->morphMany(Document::class, 'owner');
}
public function refreshVerificationStatus()
{
$this->load('documents');
$hasDocs = $this->documents()->count() > 0;
$allDocsVerified = $hasDocs && $this->documents()->where('is_verified', 0)->count() == 0;
$this->is_verified = $allDocsVerified;
$this->save();
}
}