Passing data to a custom page that includes the Filament menu system
Situation
While the majority of my single Admin panel works well in Filament, I need a report writer that allows users to select fields and build their own reports. Since I can't find this in Laravel/Filament, I want to use a non-Laravel Class I wrote and port it. So I need to create a page that has my Filament menu but allows me to write typical Controller code that passes values into a generic View that's built to display a report.
Trying this method
I'm trying to use the Pages doc (https://filamentphp.com/docs/3.x/panels/pages) in Laravel 12 w/ Filament v3 using
php artisan make:filament-page
I have created a working page that also has the menu on it.
Problem
Being better at Laravel than Filament, I'm looking for the 'controller' function that would call the 'view'. I do see the Page code that begins with class RunReport extends Page,
, but it's got no functions in it, and it magically displays the View just fine. Should I put a function in this class? If so, what should it's name be? I feel like I may be missing the point here, as the docs don't seem to address this.
Question
While I'm super impressed with Filament, I now need to put it into 'manual' mode so I can run some code before the View is called, and I can't figure out where this is put. Can someone point me in the right direction? Or if I'm not using the right solution to the problem, please point be in the right direction. I'm happy to share code if that helps.
TIA,
Dave9 Replies
So this is more a Livewire than filament question 😉
So the custom page is created and now you can open up the custom page blade file that was created when you created the custom page.
You can then call the view in here as normal. But I'd probably have migrated the old method to a livewire method depending on what the old method looked like.
Before the view is called you would do this in render before rendering the view or mount before getting to render
Does tha thelp
I think so - thanks 😉
However, I think I may be going about this the wrong way. Since I have built 80% of my application using Filament (love it!), I would like to do this "the Filament way".
So I'll reframe the question: If I need to build some classic Laravel Resource/Blade code, what's the best way for me to make it appear in the Filament menu so the user sees it as a single application?
If it helps, I have already experimented with a Controller/Resource that works well along side Filament, but I can't figure out how to add the URL for the pages into the Filament menu so the page looks like it belongs to the main app. But maybe this is the wrong approach?
Any guadance is appreciated.
It sounds like you just need to build a standard Filamentphp Custom Page, that adds into the menu and is a blade rendered view. You can add content as normal in blades But you can also add actions etc as part of the livewire methods for handling and processing data
Gotcha - so I'm on the right track - that's great!
So my question is, I've built the custom page, but it doesn't get created with functions. In the Laravel Resources I'm used to using, there's an
edit()
and a save()
, etc, and I know what they all do. Their names are special so that they hook into things like display a page, and accepting a POST from a Form.
In a Filament custom page, what do I name the functions? I've tried index()
and that doesn't seem to work, so I would guess there are special names for the functions. I would also assume there is one that when I call the URL the function is auto-loaded, and then I can call the Blade from the function.
Any clues as to how what these functions names would be or how they would work? I don't see that in the docs.If you have a custom page then the logic to save etc is up to you. There’s no preset naming. With a custom page you define everything. It’s just a livewire component in a filament shell.
Ah, sounds like I was overthinking it. Thanks!
I'll go ahead and make the routes in web.php and take it from there.
@toeknee I'm still struggling with this. Do you know of a simple example of the code I need to make this (Page with business logic and View) work? I'm one of those learners that need to see the code to understand it.
TIA
@Stricks there’s loads out there. But here’s and example:
https://filamentcomponents.com/blog/how-to-create-a-custom-profile-page-with-filamentphp
Filament Components
Filament Components | How to create a custom Profile page with Fila...
Creating a simple Filament page is not a challenge, anyone can run the command and there you have it .... but configuring and customising the page can sometime become challenging. Let's take it step by step and demystify the customisation.
Thank you!
Solution
I've got it working. That page above was immensely helpful - thanks again!