Add optional parameter to register page - won't render form
I need to add support for an optional passed affiliate code to the user registration process so I created a custom page that extends the
Filament\Pages\Auth\Register.php
class with a mount()
function that accepts an optional parameter and created a new route in web.php as follows:-
Route::get( '/register/{code?}', [\App\Filament\Pages\Auth\Register::class, 'mount'] )
->name( 'filament.public.auth.register');
The name replaces the name of the standard Filament generated route. So far so good...
When I enter the default path with no code i.e. <url>/register
I can see that the new mount is being called and the code is being defaulted and the form is rendered no problem. However as soon as I append a code i.e. <url>/register/1234
the new mount()
method is called fine but the form (or view) does not render i.e. it is a completely empty page with no mark up at all..
I tried adding an override render() method but it does not get called at all and there is nothing logged by Laravel and no JS/LW errors logged either...
Is there something I have missed?1 Reply
I managed to sort this out however discovered in the process that if a custom route is defined in
web.php
that overrides an existing Filament defined route then Livewire tries to load the class under App/LiveWire
when a call back is performed.
This is because it (Livewire's ComponentRegistry) gets passed the route name not the class name for some reason. So when a route name is passed it tries to resolve the class using App/Livewire
as the root so it fails.
Posted as this may help someone else with a similar issue...