Docs / Laravel Cart / Events

Events

The package provides a few events that you can listen to in order to manipulate the cart or take actions based on cart events.

Every event dispatches with two arguments: an $eventData array and the Cart instance itself.

$eventData always contains session_key, session_driver, and session_model. Item-scoped events (Adding, Added, Updating, Updated, Removing, Removed) also include an item key holding the relevant item data.

Event::listen('LaravelCart.Added', function (array $eventData, \Wearepixel\Cart\Cart $cart) { $item = $eventData['item']; // });

The Adding, Updating, Removing, and Clearing events are dispatched with $halt = true - returning false from a listener cancels the operation.

LaravelCart.Created

This fires every time a cart is instantiated (i.e every time the Cart class is resolved from the container).

Event::listen('LaravelCart.Created', function (array $eventData, $cart) { // cart was created });

LaravelCart.Adding

This fires every time an item is being added to the cart. Return false to cancel the add.

Event::listen('LaravelCart.Adding', function (array $eventData, $cart) { // $eventData['item'] is being added });

LaravelCart.Added

This fires every time an item is successfully added to the cart

Event::listen('LaravelCart.Added', function (array $eventData, $cart) { // $eventData['item'] was added });

LaravelCart.Updating

This fires every time an item is being updated. Return false to cancel the update.

Event::listen('LaravelCart.Updating', function (array $eventData, $cart) { // $eventData['item'] is being updated });

LaravelCart.Updated

This fires every time an item is successfully updated

Event::listen('LaravelCart.Updated', function (array $eventData, $cart) { // $eventData['item'] was updated });

LaravelCart.Removing

This fires every time an item is being removed. Return false to cancel the removal.

Event::listen('LaravelCart.Removing', function (array $eventData, $cart) { // $eventData['item'] is being removed });

LaravelCart.Removed

This fires every time an item is successfully removed

Event::listen('LaravelCart.Removed', function (array $eventData, $cart) { // $eventData['item'] was removed });

LaravelCart.Clearing

This fires every time the cart is being cleared, from both clear() and clearItems(). Return false to cancel.

Event::listen('LaravelCart.Clearing', function (array $eventData, $cart) { // cart is being cleared });

LaravelCart.Cleared

This fires every time the cart is successfully cleared, from both clear() and clearItems().

Event::listen('LaravelCart.Cleared', function (array $eventData, $cart) { // cart was cleared });
Discovery Call

One call.
We'll both know.

20 minutes to walk through your project, ask the hard questions, and work out honestly if we're the right team for it.

  • One call per day - it gets our full attention
  • Australia's only Laravel Premier Partner
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen