Docs / Laravel Cart / Storage Drivers

Storage Drivers

The cart supports multiple storage backends via a driver system.

Session (default)

Cart data is stored in the Laravel session. No configuration needed.

Database

Store the cart in a database table for persistence across sessions.

1. Create a migration:

$table->string('session_id'); $table->text('items'); $table->text('conditions');

2. Add casts to your model:

protected $guarded = []; protected $casts = [ 'items' => 'array', 'conditions' => 'array', ];

3. Update config/cart.php:

'driver' => 'database', 'drivers' => [ 'database' => [ 'model' => \App\Models\Cart::class, 'id' => 'session_id', 'items' => 'items', 'conditions' => 'conditions', ], ],

Redis

Store the cart in Redis with an optional TTL.

'driver' => 'redis', 'drivers' => [ 'redis' => [ 'connection' => 'default', 'ttl' => 604800, // 7 days in seconds ], ],

Multi-driver

Write to multiple drivers simultaneously. Reads come from the first driver listed.

'driver' => 'multi', 'drivers' => [ 'multi' => ['session', 'database'], ],

Custom driver

Generate a custom driver stub with php artisan cart:make:driver MyDriver then register it in CartManager.

Discovery Call

One call.
We'll both know.

An hour 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