HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
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();
    }
}