Skip to content

Installation

Install the package via Composer, publish the migrations and run them:

Terminal window
composer require cyrildewit/eloquent-viewable:^9
php artisan vendor:publish --provider="CyrildeWit\EloquentViewable\EloquentViewableServiceProvider" --tag="migrations"
php artisan migrate

This publishes six migrations, one per table: the views table and the tables that retention, rollups, pairs, milestones and spikes use. Those features stay off until you configure them, so their tables stay empty until then. You can delete the migration of a feature you will not use before running it. Publishing again adds only the migrations whose files are missing.

Optionally publish the config file:

Terminal window
php artisan vendor:publish --provider="CyrildeWit\EloquentViewable\EloquentViewableServiceProvider" --tag="config"

Once it is set up, php artisan views:doctor checks the setup and says what to fix.

The migration follows your application’s morph key type, so if you already call Schema::morphUsingUuids() or Schema::morphUsingUlids() it needs no changes. Otherwise edit the published migration before running it:

$table->uuidMorphs('viewable'); // or ulidMorphs('viewable')
$table->nullableUuidMorphs('viewer'); // or nullableUlidMorphs('viewer'), to match your user model

All viewable models share one viewable_id column, so they need the same key type.