File manager - Edit - /home/autoph/public_html/projects/aha-api/app/Models/Vehicle.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Auditable as AuditableTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; class Vehicle extends Model implements Auditable { use HasFactory, SoftDeletes, AuditableTrait; /** * The attributes that are NOT mass assignable. * */ protected $guarded = ['deleted_at']; /** * The attributes that should be cast. * * @var array<string, string> */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', 'owner_id' => 'integer', ]; protected $appends = ['name']; private $foreignKey = 'owner_id'; private $ownerKey = 'id'; public function getNameAttribute() { return $this->description . ' (Plate No.: ' . $this->plate_no . ')'; } public function getOwnerIdAttribute($value) { if($value == null || $value==0) { // $this->foreignKey = 'aha_user_id'; // $this->ownerKey = 'aha_user_id'; $customer = Customer::where('aha_user_id', $this->aha_user_id)->first(); $value = $customer->id ?? null; } return $value; } /** * Get the Owner of the Vehicle * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function owner() { if ($this->owner_id === null || $this->owner_id == 0) { return $this->belongsTo(Customer::class, 'aha_user_id', 'aha_user_id'); } return $this->belongsTo(Customer::class, 'owner_id', 'id'); } /** * Get the Brand of the Vehicle * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function brand() { return $this->belongsTo(Brand::class, 'brand_id'); } /** * Get the Car Line/ Model of the Vehicle * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function model() { return $this->belongsTo(CarLine::class, 'model_id'); } /** * The details of the vehicle. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function details() { return $this->hasMany(VehicleDetail::class, 'vehicle_id'); } public function bookings() { return $this->hasMany(ServiceBooking::class, 'vehicle_id'); } }
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings