定制 felixdorn/onboard 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

felixdorn/onboard

Composer 安装命令:

composer require felixdorn/onboard

包简介

Track user onboarding steps.

README 文档

README

Tests Formats Version Total Downloads License

Installation

Requires PHP 8.1+ and Laravel 8.x or 9.x

You can install the package via composer:

composer require felixdorn/onboard

Publish the ResumeOnboarding middleware to your app/Http/Middleware directory:

php artisan onboard:middleware

If you're using Inertia, you need to return false when $request->inertia() is true in the skip method of the middleware.

    public function skip(Request $request): bool
    {
        if ($request->inertia()) {
            return false;
        }
        
        return parent::skip($request);
    }

Add it to your app/Http/Kernel.php:

    // ...

    protected $middlewareGroups = [
        'web' => [
            // ...
            \App\Http\Middleware\ResumeOnboarding::class
        ]   
    ]

Then, make sure that your User model uses HasOnboarding.

use Felix\Onboard\Concerns\HasOnboarding;

class User extends Authenticatable {
    use HasOnboarding;
    
    // ...
}

You're all set.

Usage

Add your onboarding steps in app/Providers/AppServiceProvider.php

If you have a lot of steps, you may consider creating an OnboardServiceProvider (don't forget to register it in config/app.php).

use \App\Models\User;
use \Felix\Onboard\Facades\Onboard;

Onboard::add('verify_email')
    ->completedIf(function (User $user) {
        return $user->hasVerifiedEmail(); // or whatever    
    })
    ->skipIf(function () {
        return $user->github_id != null;
    })
    ->route('verification.notice')
    ->allowRoutes(['verification.verify']);

class HomeController extends Controller {
    public function index(\Illuminate\Http\Request $request) {
        return [
            'steps' => $request->user()->onboarding()->toArray()
        ];
    }
}

WARNING: Be careful, closure are memoized (their result are cached) for the duration of a request. This should never be an issue in traditional apps, if you encounter problems, please let us know.

You may call completedIf and skipIf many times, the step will be marked as completed or skipped if all the closures return true.

You may pass a closure to resolve a route lazily:

Onboard::add('create_team')
    ->route(fn () => route('teams.create'));

Globally allowed routes

Regardless of the state of the onboarding process, you may want the user to have access to certain urls, such as a logout page.

Onboard::allow(['/api/*']);

Onboard::allowRoutes(['logout', 'settings.billing']);

Step::allow and Onboard::allow make use of honda/url-pattern-matcher, check it out for more details about how to use pattern matching with Onboard.

Testing

composer test

Onboard for Laravel was created by Félix Dorn under the MIT license.

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固