You can install the package via composer:
composer require wistrix/laravel-onboard
Add the Wistrix\Onboard\Concerns\Onboardable
interface and Wistrix\Onboard\Concerns\Onboard
trait to your desired models.
...
use Wistrix\Onboard\Concerns\Onboardable;
use Wistrix\Onboard\Concerns\Onboard;
...
class User extends Model implements Onboardable
{
use Onboard;
...
You can configure your onboarding steps by using the Wistrix\Onboard\Facades\Onboard
facade. Use the default App\Providers\AppServiceProvider.php
or create a new service provider.
...
use App\Models\User;
use Wistrix\Onboard\Facades\Onboard;
...
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Onboard::register(
model: User::class,
route: 'onboarding.name',
validate: fn (User $model) => ! empty($model->name)
);
Onboard::register(
model: User::class,
route: 'onboarding.username',
validate: fn (User $model) => ! empty($model->username)
);
}
}
Create a new middleware and extend the abstract Wistrix\Onboard\Middleware
class.
use Illuminate\Http\Request;
use Wistrix\Onboard\Concerns\Onboardable;
use Wistrix\Onboard\Middleware;
class UserOnboarding extends Middleware
{
/**
* Get the onboardable model.
*
* @param Request $request
* @return Onboardable|null
*/
protected function uses(Request $request): ? Onboardable
{
return $request->user();
}
}
By default, the Wistrix\Onboard\Middleware
class defines the default route home
to redirect users too, if the onboarding is complete and a step route is accessed. This can be customised by adding the defaultRoute
method to your middleware.
/**
* Get the default route.
*
* @return string
*/
protected function defaultRoute(): string
{
return 'home';
}
You can define routes to be ignored by adding the ignoreRoutes
method. This is useful if you have registered your middleware via the bootstrap/app.php
configuration and want to ignore the logout
route for example.
/**
* Get the ignore routes.
*
* @return array
*/
protected function ignoreRoutes(): array
{
return ['logout'];
}
composer test
Please see CHANGELOG for more information.
If you discover a security vulnerability, please raise a GitHub issue.
The MIT License (MIT).
Please see License File for more information.