Tour Storage Drivers
Laravel Driver.js supports multiple storage drivers for persisting tour completion data. Choose the driver that best fits your application's needs.
Available Drivers
| Driver | Description | Persistence | Auth Required |
|---|---|---|---|
session | Stores in Laravel session | Until browser closes | No |
cache | Stores in Laravel cache | Configurable TTL (default: 1 year) | No |
database | Stores in database table | Permanent (until reset) | Yes |
null | Disables tracking | N/A | N/A |
Configuration
Set the storage driver in config/driverjs.php:
'storage' => [
'driver' => env('DRIVERJS_STORAGE_DRIVER', 'session'),
'key_prefix' => 'driverjs_tour_',
'cache_store' => env('DRIVERJS_CACHE_STORE', null),
],Session Driver (Default)
The session driver stores tour completion data in the user's session. It's the simplest option and requires no additional setup.
Pros: Zero configuration, works for all users (guest and authenticated). Cons: Data is lost when the session expires (browser closes or session lifetime ends).
'storage' => [
'driver' => 'session',
'key_prefix' => 'driverjs_tour_',
],Cache Driver
The cache driver stores tour completion data in Laravel's cache system. It persists across sessions and can use any cache store (file, redis, memcached, etc.).
Pros: Persists across sessions, fast reads/writes, supports all Laravel cache backends. Cons: Can be cleared when the cache is flushed.
'storage' => [
'driver' => 'cache',
'key_prefix' => 'driverjs_tour_',
'cache_store' => 'redis', // Optional: use a specific cache store
],When cache_store is set to null, the default cache store from config/cache.php is used. The default TTL is 1 year.
Database Driver
The database driver stores tour completion data in a database table. This is the most persistent option and supports querying completion data across all users.
Pros: Most persistent, queryable across users, never lost. Cons: Requires a database migration, only works for authenticated users.
Setup
- Set the driver to
database:
'storage' => [
'driver' => 'database',
],- Publish and run the migration:
php artisan vendor:publish --tag=driverjs-migrations
php artisan migrate- Ensure users are authenticated before tours are tracked. The driver uses
auth()->id()to associate completions with users.
Database Schema
The driverjs_tour_completions table has the following structure:
| Column | Type | Description |
|---|---|---|
id | bigint | Auto-incrementing primary key |
user_id | bigint | Foreign key to users table |
tour_name | string | The tour identifier |
completed_at | timestamp | When the tour was completed |
created_at | timestamp | Record creation timestamp |
updated_at | timestamp | Record update timestamp |
A unique constraint on (user_id, tour_name) prevents duplicate records.
Null Driver
The null driver disables tour completion tracking entirely. Tours will always be rendered regardless of how many times a user has seen them.
'storage' => [
'driver' => 'null',
],Key Prefix
The key_prefix option controls the prefix used for storage keys. This is useful if you have multiple applications sharing the same session or cache storage and want to avoid key collisions.
'key_prefix' => 'driverjs_tour_', // Keys: driverjs_tour_onboarding, driverjs_tour_dashboard, etc.That's it! You're now equipped to configure tour storage drivers using Laravel Driver.js.