Add the setCompany method in the Cart model.

This commit is contained in:
2023-06-18 18:34:19 +03:00
parent 8cdd2f2bbe
commit a8559a52c6
+16 -1
View File
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\City;
use App\Models\Company;
use Brick\Math\BigInteger;
class Cart extends Model
@@ -52,7 +53,21 @@ class Cart extends Model
$this->save();
}
public function addItem(BigInteger $item) {
public function setCompany(Company $company)
{
if($this->company_id == $company->id)
return;
$this->company_id = $company->id;
if(!$this->isEmpty())
$this->dropItems();
$this->save();
}
public function addItem(BigInteger $item)
{
$this->items()->sync($item);
}