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.