From 814eb18028ed3be0b19323b7d69346077a7a9802 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 18 Jun 2023 16:15:22 +0300 Subject: [PATCH] Update the setCity method in the Cart model. --- app/Models/Cart.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index 283b9b0..f5cc164 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -7,12 +7,17 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use App\Models\City; + class Cart extends Model { use HasFactory; protected $fillable = [ 'status', // CART | DONE + 'user_id', + 'city_id', + 'company_id' ]; public function city(): BelongsTo @@ -34,11 +39,11 @@ class Cart extends Model return $this->items()->isEmpty(); } - public function setCity($city) { - if($this->city == $city) + public function setCity(City $city) { + if($this->city_id == $city->id) return; - $this->city = $city; + $this->city_id = $city->id; if(!$this->isEmpty()) $this->dropItems();