Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CodyMcCode's avatar

Sending users through a onboarding flow in Filament

I want to force all users through a registration flow composed of 3 stages.

I essentially want to see if a user (already registered) has completed certain forms and steps.

  1. A form that must have certain selections.
  2. A 3rd party signing service (bold sign) that will chuck back a webhook when completed.
  3. Setup a subscription with Cashier.

Essentially, my question is, what is the best way of my "intercepting" and request to any page and force them through this flow? Only routing fully when the user is "fully setup".

Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

To achieve this registration flow in Filament, you can use middleware to intercept requests and check if the user has completed the required steps. If the user hasn't completed the steps, you can redirect them to the appropriate step in the registration flow.

Here's a step-by-step solution:

  1. Create Middleware to Check Registration Steps:

    First, create a middleware that will check if the user has completed the required steps.

    php artisan make:middleware CheckRegistrationSteps
    

    In the generated middleware file (app/Http/Middleware/CheckRegistrationSteps.php), you can add logic to check the user's progress.

  2. Define Methods to Check Completion of Each Step:

    In your User model, define methods to check if the user has completed each step.

    namespace App\Models;
    
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
    class User extends Authenticatable
    {
        // Other model methods...
    
        public function hasCompletedStep1()
        {
            // Check if the user has completed step 1
            return $this->step1_completed;
        }
    
        public function hasCompletedStep2()
        {
            // Check if the user has completed step 2
            return $this->step2_completed;
        }
    
        public function hasCompletedStep3()
        {
            // Check if the user has completed step 3
            return $this->step3_completed;
        }
    }
    
  3. Register Middleware:

    Register the middleware in your app/Http/Kernel.php file.

    protected $routeMiddleware = [
        // Other middleware...
        'check.registration.steps' => \App\Http\Middleware\CheckRegistrationSteps::class,
    ];
    
  4. Apply Middleware to Routes:

    Apply the middleware to the routes you want to protect. For example, in your routes/web.php file:

    Route::group(['middleware' => ['auth', 'check.registration.steps']], function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
        // Other protected routes...
    });
    
    Route::get('/registration/step1', [RegistrationController::class, 'step1'])->name('registration.step1');
    Route::get('/registration/step2', [RegistrationController::class, 'step2'])->name('registration.step2');
    Route::get('/registration/step3', [RegistrationController::class, 'step3'])->name('registration.step3');
    
  5. Handle Webhook for Step 2:

    For the 3rd party signing service webhook, create a route and controller to handle the webhook.

    Route::post('/webhook/boldsign', [WebhookController::class, 'handleBoldSign'])->name('webhook.boldsign');
    

    In the WebhookController:

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    class WebhookController extends Controller
    {
        public function handleBoldSign(Request $request)
        {
            // Handle the webhook and mark step 2 as completed for the user
            $user = User::find($request->user_id);
            $user->step2_completed = true;
            $user->save();
    
            return response()->json(['status' => 'success']);
        }
    }
    
  6. Setup Subscription with Cashier:

    For setting up a subscription with Cashier, you can handle this in the controller for step 3.

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Laravel\Cashier\Cashier;
    
    class RegistrationController extends Controller
    {
        public function step3(Request $request)
        {
            $user = Auth::user();
    
            // Handle subscription setup with Cashier
            $user->newSubscription('default', 'price_id')->create($request->paymentMethod);
    
            // Mark step 3 as completed
            $user->step3_completed = true;
            $user->save();
    
            return redirect('/dashboard');
        }
    }
    

By following these steps, you can ensure that users are forced through the registration flow and only allowed to access other parts of the application once they have completed all the required steps.

Please or to participate in this conversation.