e289fbc068
Vehicle model now implements HasMedia + InteractsWithMedia and
registers a 'photos' collection. VehicleResource form gets a
SpatieMediaLibraryFileUpload section (collapsible, max 6 photos,
imageEditor enabled).
Dashboard already checks vehicle->getFirstMediaUrl('photos') first
and falls back to the WO's photos, so uploading here immediately
populates the vehicle card on the dashboard without any view changes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenant;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use App\Models\Concerns\Auditable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
|
|
class Vehicle extends Model implements HasMedia
|
|
{
|
|
use Auditable, BelongsToTenant, InteractsWithMedia, SoftDeletes;
|
|
|
|
public const BODY_TYPES = [
|
|
'sedan' => 'Sedan', 'hatchback' => 'Hatchback', 'suv' => 'SUV',
|
|
'crossover' => 'Crossover', 'pickup' => 'Pickup', 'van' => 'Van',
|
|
'truck' => 'Camion', 'coupe' => 'Coupé', 'wagon' => 'Break',
|
|
'convertible' => 'Cabrio', 'minivan' => 'Minivan', 'moto' => 'Motocicletă',
|
|
];
|
|
|
|
public const TRANSMISSION_TYPES = [
|
|
'manual' => 'Manuală',
|
|
'automatic' => 'Automată',
|
|
'cvt' => 'CVT',
|
|
'dsg' => 'DSG',
|
|
'dct' => 'DCT (Dual-Clutch)',
|
|
'amt' => 'AMT (Robot)',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'company_id', 'client_id',
|
|
'make', 'model', 'year', 'vin', 'plate',
|
|
'engine', 'gearbox', 'fuel', 'vehicle_class', 'body_type', 'transmission_type',
|
|
'mileage', 'color', 'notes',
|
|
];
|
|
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Client::class);
|
|
}
|
|
|
|
public function getDisplayNameAttribute(): string
|
|
{
|
|
return trim("{$this->make} {$this->model} " . ($this->year ?: ''));
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('photos');
|
|
}
|
|
}
|