Skip to content

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

DriverDescriptionPersistenceAuth Required
sessionStores in Laravel sessionUntil browser closesNo
cacheStores in Laravel cacheConfigurable TTL (default: 1 year)No
databaseStores in database tablePermanent (until reset)Yes
nullDisables trackingN/AN/A

Configuration

Set the storage driver in config/driverjs.php:

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).

php
'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.

php
'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

  1. Set the driver to database:
php
'storage' => [
    'driver' => 'database',
],
  1. Publish and run the migration:
bash
php artisan vendor:publish --tag=driverjs-migrations
php artisan migrate
  1. 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:

ColumnTypeDescription
idbigintAuto-incrementing primary key
user_idbigintForeign key to users table
tour_namestringThe tour identifier
completed_attimestampWhen the tour was completed
created_attimestampRecord creation timestamp
updated_attimestampRecord 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.

php
'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.

php
'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.