PHPackages                             wfeller/laravel-onboard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wfeller/laravel-onboard

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wfeller/laravel-onboard
=======================

Track onboarding steps for users when they get setup in your app.

4.3.0(10mo ago)199.5k5[3 issues](https://github.com/wfeller/laravel-onboard/issues)MITPHPPHP ^7.4|^8.0

Since Jan 14Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/wfeller/laravel-onboard)[ Packagist](https://packagist.org/packages/wfeller/laravel-onboard)[ RSS](/packages/wfeller-laravel-onboard/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

Laravel Onboard
===============

[](#laravel-onboard)

[![Plant Tree](https://camo.githubusercontent.com/82b7e7c30d073f74b47bbaaf70f5f98792426ff1bea8ee7b05c5879ac56a060c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d627269676874677265656e266c6162656c3d506c616e74253230547265652671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e6561727468253246757365727325324674726565776172652532467472656573)](https://plant.treeware.earth/wfeller/laravel-onboard)[![Buy us a tree](https://camo.githubusercontent.com/15453546808b5ea47b48633f72f490420e2e41b885556eee95d7e88f4a754418/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666f722d7468652d6261646765)](https://plant.treeware.earth/wfeller/laravel-onboard)

A Laravel package to help track user onboarding steps.

##### Based on [calebporzio/onboard](https://github.com/calebporzio/onboard).

[](#based-on-calebporzioonboard)

Licence
-------

[](#licence)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/wfeller/laravel-onboard) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here [offset.earth/treeware](https://plant.treeware.earth/%7Bvendor%7D/%7Bpackage%7D)

Read more about Treeware at [treeware.earth](http://treeware.earth)

Installation:
-------------

[](#installation)

- Install the package via composer

```
composer require wfeller/laravel-onboard
```

- Add the `WF\Onboard\GetsOnboarded` trait to your app's User model

```
class User extends Model
{
    use \WF\Onboard\GetsOnboarded;
    // ...
}
```

Example Configuration:
----------------------

[](#example-configuration)

Configure your steps in your `App\Providers\AppServiceProvider.php`

```
    public function boot()
    {
        // This step will only apply to User::class:
        OnboardFacade::addStep('Create your first post', User::class)
            ->link('/post/create')
            ->cta('Create Post')
            // ->cacheResults() // You can cache the results to avoid duplicating queries
            ->completeIf(function (User $user) {
                // This will make 1 DB query each time to retrieve the count
                // The result will be cached if using cacheResults()
                return $user->posts()->count() > 0;
            })
            // You may add a scope to only fetch users having completed this step
            // This scope will be used when querying User::onboarded()->get()
            ->completeScope(function (Builder $builder) {
                $builder->whereHas('posts');
            })
            // All steps are required by default for all users, but you can change this behaviour
            ->requiredIf(function (User $user) {
                return $user->type === 'writer';
            })
            // You may translate your required method into a DB where clause.
            // If you don't, your completeScope (i.e. $builder->whereHas('posts')) will be called on all Users
            ->requiredScope(function (Builder $builder) {
                $builder->where('type', 'writer');
            });
    }
```

Usage:
------

[](#usage)

Now you can access these steps along with their state wherever you like. Here is an example blade template:

```
@if (Auth::user()->onboarding()->inProgress())

        @foreach (Auth::user()->onboarding()->steps as $step)

                @if($step->complete())

                    {{ $loop->iteration }}. {{ $step->title }}
                @else

                    {{ $loop->iteration }}. {{ $step->title }}
                @endif

            complete() ? 'disabled' : '' }}>
                {{ $step->cta }}

        @endforeach

@endif
```

Check out all the available features below:

```
User::onboarded()->get()->each->notify(new OnboardingComplete);
// User::onboarded(true by default)
User::onboarded(false)->get()->each->notify(new OnboardingIncomplete);

$onboarding = Auth::user()->onboarding();

$onboarding->inProgress();
$onboarding->finished();
$onboarding->finishedRequired();
$onboarding->nextUnfinishedStep();
$onboarding->step($code); // returns the step you're looking for

$onboarding->steps()->each(function($step) {
    $step->code;
    $step->title;
    $step->cta;
    $step->link;
    $step->complete();
    $step->incomplete();
    $step->required();
    $step->optional();
});
```

Definining custom attributes and accessing them:

```
// Defining the attributes
// Closures will be resolved using the given onboarding user as their only argument
OnboardFacade::addStep('Step w/ custom attributes', User::class)
    ->setAttributes([
        'name' => 'Waldo',
        'shirt_color' => 'Red & White',
        'shirt_price' => function (User $user) {
            return $user->age * 4; // yes, that example sucks :)
        },
    ]);

// Accessing them
$step->name;
$step->shirt_color;
$step->shirt_price;
```

Example middleware
------------------

[](#example-middleware)

If you want to ensure that your user is redirected to the next unfinished onboarding step, whenever they access your web application,
you can use the following middleware as a starting point:

```
