PHP code example of spatie / laravel-livewire-onboard
1. Go to this page and download the library: Download spatie/laravel-livewire-onboard library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / laravel-livewire-onboard example snippets
use App\User;
use Spatie\Onboard\Facades\Onboard;
Onboard::addStep('Complete Profile')
->link('/profile')
->cta('Complete')
->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;
});
class User extends Model implements \Spatie\Onboard\Concerns\Onboardable
{
use \Spatie\Onboard\Concerns\GetsOnboarded;
...
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;
});
Onboard::addStep('Limited Step', User::class)
->link('/post/create');
// or
Onboard::addStep('Limited Step', 'App\Models\User')
->link('/post/create');
// Defining User steps
Onboard::addStep('Limited User Step', User::class)
->link('/post/create');
// Defining Team steps
Onboard::addStep('Limited Team Step', Team::class)
->link('/post/create');
// Defining a step that is available to all classes
Onboard::addStep('Normal Step')
->link('/post/create');
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);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.