GithubHelp home page GithubHelp logo

onboard's Introduction

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.

onboard's People

Contributors

calebporzio avatar carusogabriel avatar ecointest avatar eduardostuart avatar fwartner avatar martindilling avatar nikazooz avatar petersuhm avatar povilaskorop avatar usamaejaz avatar wilburpowery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onboard's Issues

Nested Models

Hello,

I love the package, but I can't seem to get it to work with nested models. Here's why:

  • My first onboarding step is to create a project
  • My second onboarding step is to create a book inside that project
  • To that end, I need the project URL from step 1 in the link of step 2

Any idea of how to accomplish that?

Thank you,
Tal Valante

Laravel 5.8 support

Are there any plans to support Laravel 5.8? I'm wondering if it requires anything besides adding it to the composer.json file or if the package actually needs to be updated?

Support Laravel 5.7.*

As the title suggests, the installation fails for laravel 5.7.*. Migration of 5.6 to 5.7 has only a few changes required. It may not even require any change for this package though I am not sure.

Unresolvable dependency resolving [Parameter #0 [ <required> $user ]] in class Calebporzio\Onboard\OnboardingManager

Hi,

I'm getting an unresolvable dependencing resolving as somehow it's not passing on the $user class properly. I'm using spark and this is my User model:

<?php

namespace App;

use Laravel\Spark\CanJoinTeams;
use Laravel\Passport\HasApiTokens;
use Laravel\Spark\User as SparkUser;
use Calebporzio\Onboard\GetsOnboarded;

class User extends SparkUser
{
    use CanJoinTeams, HasApiTokens, GetsOnboarded;

How to reduce queries?

Implemented per instructions, and it works great, however I'm getting a huge jump in the number of queries - specifically the number of duplicated queries.

For example, on my dashboard I had 7 queries, 2 duplicated. After adding 8 Onboarding steps I have 28queries, 23 duplicated.

Any idea why the high number of duplicate queries?

Class 'App\Providers\Onboard' not found

Got Fatal Error when adding

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

in App\Providers\AppServiceProvider.php

Unable to redirect back to a step, getting ERR_TOO_MANY_REDIRECTS

My setup looks like following.

AppServiceProvider.php

OnboardFacade::addStep('Connect Slack App')
    ->link('/connect-slack')
    ->cta('Complete')
    ->completeIf(function (User $user) {
        return $user->hasTaskCreator('slack');
    });

Added middleware in my krenel.php under web

...
\App\Http\Middleware\RedirectToUnfinishedOnboardingStep::class,
...

When logged in I am redirected to proper link /connect-slack.

But it's a 404 because there is no route as /connect-slack. When I add a route in my web.php and try to visit the page I get too many redirects.

This is how I connect view to the route.

Route::get('/connect-slack', function () {
    return view('onboarding.slack-connect');
})->name('connect-slack');

How can I add the view to the route?

array_get() deprecated in Laravel 6.x

Hi,

I've tried to test this package in Laravel 6.0.x and it isn't working, because array_get() is no longer available in Laravel helpers of version 6.x.

Call to undefined function Calebporzio\Onboard\array_get()

I hope that helps!

Installation on Laravel Version 5.7.* still fails

I still cannot install this package using composer and Laravel 5.7

This is my error stacktrace:

Your requirements could not be resolved to an installable set of packages.

Problem 1
  - Conclusion: don't install calebporzio/onboard v1.1.1
  - Conclusion: remove laravel/framework v5.7.20
  - Installation request for calebporzio/onboard ^1.1 -> satisfiable by calebporzio/onboard[v1.1, v1.1.1].
  - Conclusion: don't install laravel/framework v5.7.20
  - calebporzio/onboard v1.1 requires laravel/framework 5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.* -> satisfiable by laravel/framework[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev].
  - laravel/framework 5.2.x-dev conflicts with laravel/framework[v5.7.20].
  - laravel/framework 5.3.x-dev conflicts with laravel/framework[v5.7.20].
  - laravel/framework 5.4.x-dev conflicts with laravel/framework[v5.7.20].
  - laravel/framework 5.5.x-dev conflicts with laravel/framework[v5.7.20].
  - Can only install one of: laravel/framework[5.0.x-dev, v5.7.20].
  - Can only install one of: laravel/framework[5.1.x-dev, v5.7.20].
  - Installation request for laravel/framework (locked at v5.7.20, required as 5.7.*) -> satisfiable by laravel/framework[v5.7.20].


Installation failed, reverting ./composer.json to its original content.

The error occurs when installing the package trough composer as mentioned on the install page

Middleware Example

I don't know where i should register the middleware inside kernel.php. Should i register it under route middleware or middlewareGroups web?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.