Add methods to add and remove Items from a Cart.

main
KKlochko 2 years ago
parent e4f003f074
commit 0c2f6355cf

@ -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 Brick\Math\BigInteger;
class Cart extends Model class Cart extends Model
{ {
@ -51,6 +52,22 @@ class Cart extends Model
$this->save(); $this->save();
} }
public function addItem(BigInteger $item) {
$this->items()->sync($item);
}
public function addItems(array $items) {
$this->items()->sync($items);
}
public function removeItem(BigInteger $item) {
$this->items()->sync($item);
}
public function removeItems(array $items) {
$this->items()->sync($items);
}
public function dropItems() { public function dropItems() {
$this->items()->detach(); $this->items()->detach();
} }

Loading…
Cancel
Save