From 38284947e09285f58466bfeb9e269281220648cb Mon Sep 17 00:00:00 2001 From: Nadim Salloum Date: Mon, 10 May 2021 19:05:46 +0200 Subject: [PATCH] add basic structure --- app/Models/Car.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/Models/Car.php b/app/Models/Car.php index 2fed267..bcb4cdb 100644 --- a/app/Models/Car.php +++ b/app/Models/Car.php @@ -8,4 +8,48 @@ use Illuminate\Database\Eloquent\Model; class Car extends Model { use HasFactory; + + protected $fillable = [ + 'variation', + 'variation', + 'vin', + 'colour', + 'notes', + 'known_damage', + 'initial_date', + 'bought_at', + 'buy_price', + 'seller_contact_id', + 'car_model_id' + ]; + + public function brand() + { + return $this->hasOneThrough(Brand::class, CarModel::class); + } + + public function carModel() + { + return $this->belongsTo(CarModel::class); + } + + public function seller() + { + return $this->belongsTo(Contact::class, 'seller_contact_id'); + } + + public function buyer() + { + return $this->hasOneThrough(Contract::class, Contact::class); + } + + public function contract() + { + return $this->hasOne(Contract::class); + } + + public function carPayment() + { + return $this->hasManyThrough(CarPayment::class, Contract::class); + } }