Add the setCompany method in the Cart model.

main
KKlochko 2 years ago
parent 8cdd2f2bbe
commit a8559a52c6

@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\City; use App\Models\City;
use App\Models\Company;
use Brick\Math\BigInteger; use Brick\Math\BigInteger;
class Cart extends Model class Cart extends Model
@ -52,7 +53,21 @@ class Cart extends Model
$this->save(); $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); $this->items()->sync($item);
} }

Loading…
Cancel
Save