Lozza's avatar
Level 4

Basic Cart - best place to start

I am looking to create a basic cart system in Laravel to facilitate purchasing of tickets for an event along with associated show tickets.

I am thinking of using Breeze and Cashier for handling the authentication and payments and am looking for suggestions for the best package(s) to start with?

Thank you

0 likes
3 replies
LaryAI's avatar
Level 58

For a basic cart system in Laravel, you can start by using the Laravel Shopping Cart package. This package provides a simple and flexible way to implement a shopping cart functionality in your Laravel application.

To get started, you can follow these steps:

  1. Install the package using Composer:
composer require gloudemans/shoppingcart
  1. Publish the package's configuration file and migration files:
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="migrations"
  1. Run the migration to create the necessary tables in your database:
php artisan migrate
  1. In your controller or wherever you want to add items to the cart, you can use the following code:
use Gloudemans\Shoppingcart\Facades\Cart;

// Add an item to the cart
Cart::add([
    'id' => 1,
    'name' => 'Product Name',
    'price' => 9.99,
    'quantity' => 1,
    'attributes' => [],
]);

// Retrieve the cart items
$cartItems = Cart::content();
  1. In your views, you can display the cart items using the following code:
@foreach($cartItems as $item)
    <p>{{ $item->name }}</p>
    <p>{{ $item->price }}</p>
    <p>{{ $item->quantity }}</p>
@endforeach

This is just a basic example to get you started with the Laravel Shopping Cart package. You can refer to the package's documentation for more advanced usage and customization options.

Note: Breeze and Cashier are great choices for authentication and payment handling, but they are not directly related to the cart functionality. You can integrate them with the cart system as per your requirements.

Please or to participate in this conversation.