Storage Options
By default the cart is stored in the session, but there are times you may want to store the cart in the database.
For instance, you may want to store the cart in the database so that the cart can be retrieved even after the user logs out or closes the browser, or you may want to add cart timeouts and support for multiple computers.
Session
The cart is stored in the session by default, using Laravel's in-built SessionManager.
Database Support
To get started, you'll need to create a new model for your Cart, the package requires only 3 columns, but you're free to extend this as you wish and add more columns.
You can utilise the events provided by the package to store additional information alongside the cart.
$table->string('session_id'); // this handles the session id of the cart
$table->text('items'); // this will store the cart items
$table->text('conditions'); // this will store the cart level conditions
Then add some json casts to your model and fillable columns:
protected $guarded = [];
protected $casts = [
'items' => 'array',
'conditions' => 'array',
];
Then update the configuration file to use the database driver:
'driver' => 'database',
'storage' => [
'session',
'database' => [
'model' => \App\Models\Cart::class, // your model here
'id' => 'session_id',
'items' => 'items',
'conditions' => 'conditions',
],
],