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

MariosIgkiempor's avatar

Using a Filament Form as the registration form for Jetstream

Is it enough to call the CreateNewUser action in App\Actions\Fortify?

Will this also send verification emails etc?

The RegisteredUserController basically just calls CreateNewUser & logs the user in, but not sure if I'm missing something else that's happening behind the scenes somewhere.

Thank you!

0 likes
1 reply
LaryAI's avatar
Level 58

To use a Filament form as the registration form for Jetstream, you can indeed call the CreateNewUser action from App\Actions\Fortify. However, you need to ensure that all the necessary steps, such as sending verification emails, are handled properly.

Here's a step-by-step solution:

  1. Create the Filament Form: First, create a Filament form for user registration.

  2. Handle Form Submission: In the form submission handler, call the CreateNewUser action and handle the additional steps like sending verification emails.

  3. Call CreateNewUser Action: Use the CreateNewUser action to create the user.

  4. Send Verification Email: After creating the user, send the verification email if your application requires email verification.

Here is an example of how you can achieve this:

use App\Actions\Fortify\CreateNewUser;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Button;
use Filament\Forms\Form;

class RegisterForm
{
    public function render()
    {
        return Form::make()
            ->schema([
                TextInput::make('name')
                    ->required()
                    ->label('Name'),
                TextInput::make('email')
                    ->required()
                    ->email()
                    ->label('Email'),
                TextInput::make('password')
                    ->required()
                    ->password()
                    ->label('Password'),
                TextInput::make('password_confirmation')
                    ->required()
                    ->password()
                    ->label('Confirm Password'),
                Button::make('Register')
                    ->submit('register')
            ])
            ->submit(function ($data) {
                $this->register($data);
            });
    }

    public function register($data)
    {
        $validator = Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);

        if ($validator->fails()) {
            // Handle validation errors
            return;
        }

        $createNewUser = new CreateNewUser();
        $user = $createNewUser->create($data);

        // Log the user in
        Auth::login($user);

        // Send verification email if required
        if (method_exists($user, 'sendEmailVerificationNotification')) {
            $user->sendEmailVerificationNotification();
        }

        // Redirect or perform any other actions
    }
}

Explanation:

  1. Form Schema:

    • Define the form fields for name, email, password, and password_confirmation.
    • Add a submit button labeled "Register".
  2. Form Submission:

    • On form submission, the register method is called with the form data.
  3. Validation:

    • Validate the form data using Laravel's Validator.
  4. Create User:

    • Use the CreateNewUser action to create the user.
  5. Login User:

    • Log the user in using Auth::login.
  6. Send Verification Email:

    • Check if the user model has the sendEmailVerificationNotification method and call it to send the verification email.

This approach ensures that the user is created, logged in, and sent a verification email if required, mimicking the behavior of Jetstream's default registration process.

Please or to participate in this conversation.