Skip to content

Getting the Cart Item Count

To retrieve the total number of items in the cart, you can use either Cart::count() or cart()->count().

Method Signatures

php
Cart::count();
Cart::count();

or

php
cart()->count();
cart()->count();

Example

Using Cart::count():

php
use RealRashid\Cart\Facades\Cart;

// Get the count of items in the cart
Cart::count();
use RealRashid\Cart\Facades\Cart;

// Get the count of items in the cart
Cart::count();

Using cart()->count():

php
// Get the count of items in the cart
cart()->count();
// Get the count of items in the cart
cart()->count();

In both examples, the method will return the total number of items in the cart.

That's it! You're now equipped to retrieve the count of items in your shopping cart using the Cart package.