PHP code example of wallacemartinss / filament-onboarding

1. Go to this page and download the library: Download wallacemartinss/filament-onboarding 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/ */

    

wallacemartinss / filament-onboarding example snippets


use Wallacemartinss\FilamentOnboarding\FilamentOnboardingPlugin;

$panel->plugins([
    FilamentOnboardingPlugin::make()
        ->launcher()                        // floating checklist, on every page
        ->tours()                           // guided tours
        ->progressPage()                    // optional page laying the journey out
        ->launcherPosition('bottom-right')  // bottom-left, top-right, top-left
        ->modalPosition('center'),          // where images and videos open
]);

FilamentOnboardingPlugin::make()
    ->manageFlows()
    ->launcher(false)
    ->tours(false)
    ->navigationGroup(fn (): string => __('navigation.system'))
    ->navigationIcon('heroicon-o-map')
    ->navigationSort(70),

// app/Onboarding/Conditions/HasActivePlanCondition.php — answers to `has_active_plan`
class HasActivePlanCondition implements OnboardingCondition, HasConditionLabel
{
    public static function label(): string
    {
        return __('Has an active plan');   // what the step editor shows
    }

    public function isCompleted(Model $subject, ?Model $scope = null): bool
    {
        return $subject->subscription()?->active() ?? false;
    }
}

Onboarding::condition('has_server', fn (User $user, ?Tenant $tenant): bool =>
    $tenant->servers()->exists()
);

Onboarding::condition('has_docker_feature', fn (User $user, ?Tenant $tenant): bool =>
    $tenant?->hasFeature('docker_services') ?? false
);

Action::make('create')->extraAttributes(['data-onboarding' => 'create-server']),

use Wallacemartinss\FilamentOnboarding\Actions\StartTourAction;

protected function getHeaderActions(): array
{
    return [
        StartTourAction::make('servers-tour'),
        Actions\CreateAction::make(),
    ];
}

StartTourAction::make([
    'servers-tour',
    'create-server-cloud-tour',
    'create-server-byos-tour',
]),

// config/filament-onboarding.php
'media' => [
    'disk'       => env('FILESYSTEM_DISK', 's3'),   // S3, R2, local — any Laravel disk
    'directory'  => 'onboarding',
    'visibility' => 'private',                      // signs a temporary URL instead of exposing the file
    'url_ttl'    => 30,
],

FilamentOnboardingPlugin::make()->modalPosition('bottom-right'),

FilamentOnboardingPlugin::make()->welcome(),

use Wallacemartinss\FilamentOnboarding\Widgets\OnboardingChecklistWidget;

// In a Dashboard page, or the panel's widgets()
OnboardingChecklistWidget::class,

FilamentOnboardingPlugin::make()
    ->progressPage()
    ->progressPageSlug('getting-started')        // default: onboarding
    ->progressPageNavigation(
        label: fn (): string => __('Getting started'),
        icon: 'heroicon-o-map',
        group: fn (): string => __('Settings'),
        sort: 90,
    ),

use Wallacemartinss\FilamentOnboarding\Facades\Onboarding;

$onboarding = Onboarding::for($user, $tenant);   // or Onboarding::current()

$onboarding->complete('first-deploy');
$onboarding->skip('invite-team');
$onboarding->uncomplete('first-deploy');
$onboarding->dismiss('getting-started');
$onboarding->restore('getting-started');
$onboarding->reset('getting-started');
$onboarding->handleVisit('/app/acme/servers/create');

$flow = $onboarding->flow('getting-started');      // or ->currentFlow()

$flow->percentage();            // 43
$flow->isCompleted();
$flow->nextStep()?->title();
$flow->steps;                   // StepState[]

use Wallacemartinss\FilamentOnboarding\Events\{StepCompleted, FlowCompleted};

FilamentOnboardingPlugin::make()
    ->subject(fn () => auth()->user())
    ->scope(fn () => Filament::getTenant())
    ->urlParameters(fn (): array => ['tenant' => Filament::getTenant()?->slug]),

FilamentOnboardingPlugin::make()
    ->skipWhen(fn (User $user): bool => $user->onboarded_at !== null),

use Wallacemartinss\FilamentOnboarding\Events\FlowCompleted;
use Wallacemartinss\FilamentOnboarding\Facades\Onboarding;

class MarkSubjectOnboarded
{
    public function handle(FlowCompleted $event): void
    {
        $done = Onboarding::for($event->subject, $event->scope)
            ->flows()
            ->every(fn ($flow): bool => $flow->isCompleted());

        if ($done) {
            $event->subject->forceFill(['onboarded_at' => now()])->save();
        }
    }
}

// app/Policies/OnboardingFlowPolicy.php
namespace App\Policies;

use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;

class OnboardingFlowPolicy extends \Wallacemartinss\FilamentOnboarding\Policies\OnboardingFlowPolicy
{
    public function viewAny(Authenticatable $user): bool
    {
        return $user instanceof User && $user->isAdmin();
    }
}

// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Gate;
use Wallacemartinss\FilamentOnboarding\Models\OnboardingFlow;

Gate::policy(OnboardingFlow::class, \App\Policies\OnboardingFlowPolicy::class);

'policies' => [
    'flow'      => \App\Policies\OnboardingFlowPolicy::class,
    'step'      => null,   // null keeps the package default
    'condition' => null,
],

'locales' => ['pt_BR', 'en', 'es'],

'title' => 'onboarding.journey.title',   // resolved through __()

'styles' => [
    'enabled' => true,
    'path'    => resource_path('css/vendor/filament-onboarding/onboarding.css'),
],
bash
composer  vendor:publish --tag=filament-onboarding-migrations
php artisan vendor:publish --tag=filament-onboarding-config
php artisan migrate
php artisan filament:assets
bash
php artisan make:onboarding-condition HasActivePlan
bash
php artisan onboarding:reset getting-started --subject=1 --scope=<tenant-id> --scope-model="App\Models\Tenant"
bash
php artisan vendor:publish --tag=filament-onboarding-styles
bash
php artisan vendor:publish --tag=filament-onboarding-views
bash
composer update wallacemartinss/filament-onboarding
php artisan vendor:publish --tag=filament-onboarding-migrations   # existing files are left alone
php artisan migrate
php artisan filament:assets