Add a method to check that an item in a cart.

This commit is contained in:
2023-06-19 18:10:54 +03:00
parent 73b45084b7
commit e91b808a0f
+11
View File
@@ -51,6 +51,17 @@ class Cart extends Model
return $this->items()->pluck('item_id')->toArray();
}
public function isItemIn(Item $item): bool
{
$itemsIds = $this->getItemIds();
$countOfMatches = Item::whereIn('id', $itemsIds)
->where('uuid', $item->uuid)
->count();
return $countOfMatches != 0;
}
public function isEmpty()
{
return count($this->getItemIds());