PHPackages                             leanmachine/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. leanmachine/laravel-onboard

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

leanmachine/laravel-onboard
===========================

A Laravel package to help track user onboarding steps

2.2.1(3y ago)057MITPHPPHP ^8.0|^8.1

Since Jun 17Pushed 3y agoCompare

[ Source](https://github.com/leanrank/laravel-onboard)[ Packagist](https://packagist.org/packages/leanmachine/laravel-onboard)[ Docs](https://github.com/leanrank/laravel-onboard)[ RSS](/packages/leanmachine-laravel-onboard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (11)Versions (11)Used By (0)

[![](https://camo.githubusercontent.com/2bedf63f24cda7efab02da955dc11fb7ef8a060e2f26b73c33a7aac84529b8a3/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31)](https://supportukrainenow.org)

A Laravel package to help track user onboarding steps
=====================================================

[](#a-laravel-package-to-help-track-user-onboarding-steps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5580cb3c072c1c2159196eec935b03ed67ba5aac8112c593cd61d1e3f0bcef35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6f6e626f6172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-onboard)[![GitHub Tests Action Status](https://camo.githubusercontent.com/52e1ec4d8ce508ad5a8282fa2deb44312a166c3563e201eaa4944bf6128aa110/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6f6e626f6172642f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/spatie/laravel-onboard/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8a0347232f354eb1c2d2a06a7398942b82a446c00aadd17026a98fa94275ebd0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6f6e626f6172642f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/spatie/laravel-onboard/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a1607e5e7d641dd5cd7548b2aa240cf608fed24351364c022adcac7ffcde7fee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6f6e626f6172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-onboard)

This package lets you set up an onboarding flow for your application's users.

Here's an example of how it's set up:

```
use App\User;
use Spatie\Onboard\Facades\Onboard;

Onboard::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;
    });
```

You can then render this onboarding flow however you want in your templates:

```
@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
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/aff7653c403b9f3fae0407691c8b97c17c31b2d3e5e6b5cf89aa4811bbce82df/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6f6e626f6172642e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-onboard)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-onboard
```

Usage
-----

[](#usage)

Add the `Spatie\Onboard\Concerns\GetsOnboarded` trait and `Spatie\Onboard\Concerns\Onboardable` interface to any model or class in your app, for example the `User` model:

```
class User extends Model implements \Spatie\Onboard\Concerns\Onboardable
{
    use \Spatie\Onboard\Concerns\GetsOnboarded;
    ...
```

### Example configuration

[](#example-configuration)

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

```
use App\User;
use Spatie\Onboard\Facades\Onboard;

class AppServiceProvider extends ServiceProvider
{
    // ...

    public function boot()
    {
	    Onboard::addStep('Complete Profile')
	    	->link('/profile')
	    	->cta('Complete')
	    	/**
             * The completeIf will pass the class that you've added the
             * interface & trait to. You can use Laravel's dependency
             * injection here to inject anything else as well.
             */
	    	->completeIf(function (User $model) {
	    		return $model->profile->isComplete();
	    	});

	    Onboard::addStep('Create Your First Post')
	    	->link('/post/create')
	    	->cta('Create Post')
	    	->completeIf(function (User $model) {
	    		return $model->posts->count() > 0;
	    	});
```

The variable name passed to the `completeIf` callback must be `$model`.

### Usage

[](#usage-1)

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:

```
/** @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();
});
```

Excluding steps based on condition:

```
Onboard::addStep('Excluded Step')
    ->excludeIf(function (User $model) {
        return $model->isAdmin();
    });
```

Definining custom attributes and accessing them:

```
// Defining the attributes
Onboard::addStep('Step w/ custom attributes')
	->attributes([
		'name' => 'Waldo',
		'shirt_color' => 'Red & White',
	]);

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

### 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:

```
