Add methods to add and remove Items from a Cart.
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\City;
|
||||
use Brick\Math\BigInteger;
|
||||
|
||||
class Cart extends Model
|
||||
{
|
||||
@@ -51,6 +52,22 @@ class Cart extends Model
|
||||
$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() {
|
||||
$this->items()->detach();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user