From 3eff14173b6983f06dd33cb3e391277357d8d5f7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Mon, 19 Jun 2023 15:05:37 +0300 Subject: [PATCH] Add getters to Cart model to get its City or Company. --- app/Models/Cart.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index fc21497..3217903 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -27,11 +27,21 @@ class Cart extends Model return $this->belongsTo(City::class); } + public function getCity(): City + { + return City::where('city_id', $this->city_id)->first(); + } + public function company(): BelongsTo { return $this->belongsTo(Company::class); } + public function getCompany(): Company + { + return Company::where('company_id', $this->company_id)->first(); + } + public function items(): BelongsToMany { return $this->belongsToMany(Item::class, 'carts_items', 'cart_id', 'item_id');