• This repository has been archived on 23/Jun/2022
  • Stars
    star
    439
  • Rank 99,247 (Top 2 %)
  • Language
    PHP
  • Created almost 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Laravel package to help track user onboarding steps.

Note: This package has been archived, you should use it's successor "Laravel Onboard" instead: https://github.com/spatie/laravel-onboard


Onboard

A Laravel package to help track user onboarding steps.

Installation:

  • Install the package via composer
composer require calebporzio/onboard
  • Register the Service Provider and Facade in config/app.php
'providers' => [
    ...
    Calebporzio\Onboard\OnboardServiceProvider::class,

'aliases' => [
    ...
    Calebporzio\Onboard\OnboardFacade::class,
  • Add the Calebporzio\Onboard\GetsOnboarded trait to your app's User model
class User extends Model
{
    use \Calebporzio\Onboard\GetsOnboarded;
    ...

Example Configuration:

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

use App\User;
use Calebporzio\Onboard\OnboardFacade;

class AppServiceProvider extends ServiceProvider
{
    // ...

    public function boot()
    {
	    OnboardFacade::addStep('Complete Profile')
	    	->link('/profile')
	    	->cta('Complete')
	    	->completeIf(function (User $user) {
	    		return $user->profile->isComplete();
	    	});

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

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())
	<div>

		@foreach (auth()->user()->onboarding()->steps as $step)
			<span>
				@if($step->complete())
					<i class="fa fa-check-square-o fa-fw"></i>
					<s>{{ $loop->iteration }}. {{ $step->title }}</s>
				@else
					<i class="fa fa-square-o fa-fw"></i>
					{{ $loop->iteration }}. {{ $step->title }}
				@endif
			</span>
						
			<a href="{{ $step->link }}" {{ $step->complete() ? 'disabled' : '' }}>
				{{ $step->cta }}
			</a>
		@endforeach

	</div>
@endif

Check out all the available features below:

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

$onboarding->inProgress();

$onboarding->finished();

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

Definining custom attributes and accessing them:

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

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

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:

<?php

namespace App\Http\Middleware;

use Auth;
use Closure;

class RedirectToUnfinishedOnboardingStep
{
    public function handle($request, Closure $next)
    {
        if (auth()->user()->onboarding()->inProgress()) {
            return redirect()->to(
                auth()->user()->onboarding()->nextUnfinishedStep()->link
            );
        }
        
        return $next($request);
    }
}

Quick tip: Don't add this middleware to routes that update the state of the onboarding steps, your users will not be able to progress because they will be redirected back to the onboarding step.

More Repositories

1

sushi

Eloquent's missing "array" driver.
PHP
2,570
star
2

awesome-helpers

Helper functions I find super-duper handy
PHP
629
star
3

gitdown

A simple package to parse Github Flavored Markdown in PHP
PHP
219
star
4

better-phpunit

A better PHPUnit test runner for VS Code
TypeScript
211
star
5

laracasts-livewire-datatable

The Laravel project I used during the "Building DataTables with Livewire" Laracasts video
PHP
118
star
6

bear-sync

Access your Bear notes in Laravel
PHP
107
star
7

tailbuild

A simple command to build a Tailwind CSS file for your project (with JIT compiling and watching)
JavaScript
89
star
8

laravel-helpers-file

Because I can never remember exactly how to autoload my helpers.php file.
PHP
61
star
9

laravel-frontend-preset

My personal frontend preset for new laravel applications.
PHP
31
star
10

laracon-online-2020

The Laravel project used in my Laracon Online 2020 talk
PHP
28
star
11

laracasts-building-alpine

JavaScript
27
star
12

simple-php-cs-fixer

A VS Code extension for simple php-cs-fixer integration
PHP
24
star
13

sps

TypeScript
20
star
14

vue-form-state

JavaScript
19
star
15

vercel-laravel

PHP
19
star
16

click

The podcast recording and editing suite of your dreams. Featuring just the one button.
Crystal
18
star
17

livewire-uncovered

PHP
13
star
18

laracasts-turbolinks

The source app from my Laracasts turbolinks video.
PHP
11
star
19

usesushi.dev

The website for sushi
PHP
10
star
20

presettings

A VS Code extension for storing and activating settings presets
TypeScript
10
star
21

laracasts-server-fetched-partials

The Laravel app used in my Laracasts episode on "Server-Fetched Partials"
PHP
10
star
22

laracasts-cached-server-fetched-partials

The finished Laravel app from my "Caching Server Fetched Partials" video.
PHP
10
star
23

vue-fetch-html

A little component for fetching html/vue/javascript from the server.
Vue
9
star
24

livewire-bot

Livewire's GitHub bot
PHP
7
star
25

laravel-acceptance-example

An example laravel project with acceptance tests that render javascript and work well with laravel's helpers.
PHP
7
star
26

model-inheritance

PHP
6
star
27

99bottles-php

PHP
4
star
28

edoc-2019

PHP
4
star
29

vue-example-component

For when you regret getting rid of the default Laravel ExampleComponent.vue
Vue
3
star
30

screendit

PHP
3
star
31

calebporzio

3
star
32

johnny

HTML
2
star
33

dotfiles

Shell
2
star
34

write-less-js

PHP
1
star
35

advent-of-code-2018

My Advent Of Code solutions for 2018
PHP
1
star
36

rm-me

1
star
37

spend-mo

JavaScript
1
star
38

psrpoetry

HTML
1
star
39

ingenuity

CSS
1
star
40

ingenuity-teaser

HTML
1
star
41

theretireddevtheme

A modified ghost (blog) theme for theretireddev.com
CSS
1
star