I have a custom page that needs to load a second page with a parameter
I have created a custom page that allows the user to select a payment plan then when they confirm it will load a second custom page with an URL parameter of the selected payment plan id so the user can confirm and load a payment form.
I cant get the second page to load the view when a parameter is passed. I created a route to load the Component's mount() function with the ID parameter and I can dump out that the parameter is being successfully passed and injected into the mount() method of the second page but the view doesn't get loaded - just a white screen with nothing logged.
If I remove the parameter and route definition then the view gets loaded..
I am new to Filament (this is V2) and Livewire so what am I missing? Why will it not load the view that is defined in the component when a parameter is passed/injected into the mount method?
TIA for any guidance!
6 Replies
Can you share the code for the second Livewire component?
Are you specifying a view in the second Livewire component? Are there any logs you can share?
I am using the code generated by Filament for a custom page - here's the component code:-
namespace App\Filament\Pages;
use Filament\Pages\Page;
class PaymentPageConfirm extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.payment-page-confirm';
protected static function shouldRegisterNavigation(): bool
{
return false;
}
public function mount( $ppid = 0 ): void
{
dump(__METHOD__.' '.$ppid );
}
}
Here's the route definition
Route::get('dashboard/payment-page-confirm/{ppid}',[App\Filament\Pages\PaymentPageConfirm::class,'mount'])
->name( 'payment.page.confirm' );
Nothing gets logged - the dump in the mount()
method displays the injected $ppid
value but then there is just a blank page... If I remove the ID from the URL and re-load it displays 0 for the ID and the view is rendered..oh I think I know what's happening
you're extending
Filament\Pages\Page
, which I'm pretty sure has it's own mount()
function
OK after more investigating I might be wrong here, but when I use php artisan make:filament-page SortUsers --resource=UserResource --type=custom
as specified in the v2 docs to make a custom page, the new custom page ends up extending use Filament\Resources\Pages\Page;
You said in your initial post you are using v2
By chance are you using v3 and this is something new?
Either way, I think the fact that you are using your own mount
function might be the issue
define a public variable with the same name public $ppid;
and then don't use your own mount
function
Livewire should automatically recognize that you're passing a value in and assign it to $ppid
Not sure if it’s the issue, but mount definitely needs to call parent::mount().
Since the Page class is the livewire component. There’s a lot of set up that goes on there.
@.rich06 Try using these methods in the page instead of defining your own routes in
routes/web.php
.
Thanks Andrew - I will try that however however if I take the route definition out of
routes/web.php
then how should I get the route in the blade component of the initial page? To hopefully explain what's happening here...in Page 1 the user selects the payment plan they want and then by clicking a confirm button they get redirected to Page 2 (which up till now was done via a named route defined in web.php
). Page 2 should get loaded via 'payment-page-confirm/{ppid}'
with the selected ppid as a parameter. Hope I am making sense here!