Wizard loses $_GET param after next step

<?php

namespace App\Filament\Pages\Auth;

use Filament\Actions\Action;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register;

class Registration extends Register
{
protected string $type = 'inwoner';

public function mount(): void
{
$this->type = request()->get('type', 'inwoner'); // inwoner or organisatie

parent::mount();
}

public function form(Form $form): Form
{
return $form
->schema([
$this->type === 'inwoner' ?
$this->getUserFormComponent() :
$this->getOrganizationFormComponent(),
]);
}
//
<?php

namespace App\Filament\Pages\Auth;

use Filament\Actions\Action;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register;

class Registration extends Register
{
protected string $type = 'inwoner';

public function mount(): void
{
$this->type = request()->get('type', 'inwoner'); // inwoner or organisatie

parent::mount();
}

public function form(Form $form): Form
{
return $form
->schema([
$this->type === 'inwoner' ?
$this->getUserFormComponent() :
$this->getOrganizationFormComponent(),
]);
}
//
$this->getOrganizationFormComponent() return Filament\Forms\Components\Wizard component. Without the ternary in the form method, clicking next works, but with the ternary and type 'organisatie' in the url, clicking next results in the default type and the form glitches because of it. How can I make sure it returns the next step correctly?
Solution:
I believe you need to use Livewires #[Url] Attribute ```php use Livewire\Attributes\Url; ...
Jump to solution
2 Replies
Solution
rhysleesdev
rhysleesdev4d ago
I believe you need to use Livewires #[Url] Attribute
use Livewire\Attributes\Url;

class Registration extends Register
{
#[Url]
protected string $type = 'inwoner';

public function mount(): void
{
parent::mount();
}

public function form(Form $form): Form
{
return $form
->schema([
$this->type === 'inwoner' ?
$this->getUserFormComponent() :
$this->getOrganizationFormComponent(),
]);
}
}
use Livewire\Attributes\Url;

class Registration extends Register
{
#[Url]
protected string $type = 'inwoner';

public function mount(): void
{
parent::mount();
}

public function form(Form $form): Form
{
return $form
->schema([
$this->type === 'inwoner' ?
$this->getUserFormComponent() :
$this->getOrganizationFormComponent(),
]);
}
}
Arjen
ArjenOP4d ago
This works, thanks! Had to change protected to public.

Did you find this page helpful?