A Package for Onboarding Users in Laravel Apps
Published on by Paul Redmond
Laravel Onboard is a Laravel package to help track user onboarding steps created by Spatie:
🚀 spatie/laravel-onboard has been released.
— Freek Van der Herten 🔭 (@freekmurze) June 21, 2022
This @laravelphp package tracks onboarding steps for new users.https://t.co/qfOeH783dL
🧑💻 @calebporzio made the first version that we now maintain. @Riasvdv did some good work polishing it
✍️ Blogpost: https://t.co/zTDsqtx60C#php pic.twitter.com/0uru4apEiU
Here's a quick example taken from the project readme on using this package to create onboarding steps:
use App\User;use Spatie\Onboard\Facades\Onboard; // You can add onboarding steps in a `boot()` method within a service providerOnboard::addStep('Complete Profile') ->link('/profile') ->cta('Complete') ->completeIf(function (User $user) { return $user->profile->isComplete(); }); Onboard::addStep('Create Your First Post') ->link('/post/create') ->cta('Create Post') ->completeIf(function (User $user) { return $user->posts->count() > 0; });
To get a user's onboarding status—among other things—the package has a nice API for accessing things like percentage complete, in progress, finished, and details about individual steps:
/** @var \Spatie\Onboard\OnboardingManager $onboarding **/$onboarding = Auth::user()->onboarding(); $onboarding->inProgress(); $onboarding->percentageCompleted(); $onboarding->finished(); $onboarding->steps()->each(function($step) { $step->title; $step->cta; $step->link; $step->complete(); $step->incomplete();});
Additionally, this package supports features such as:
- Conditionally excluding steps with custom logic
- Defining custom attributes on a step
- Use middleware to ensure a user completes onboarding before they are allowed to use certain features
- And more
You can get started with this package by checking it out on GitHub at spatie/laravel-onboard. Their blog post can also give you some examples and further details on how you can use this package.