Custom Page
I want to create a custom page where a user can execute a specific sql query, I created the custom page and linked it so from user resource they can get to it from head actions. The user is :
However I cant find any documentation on how to execute a specific sql query on my custom page or show the results using table builder.
18 Replies
I think this could be a bit complicated, because the table expects a query in the context of a specific Eloquent model. I'm not sure how it could support an arbitrary SQL query, with ad-hoc columns, etc.
A good place to start would be to have a textarea for the SQL query and simply display the results in an HTML table.
It's a custom page so maybe query could be run in the mount method. It depends what's the result and query is
@Patrick Boivin The query would be coded into the page sorry not given by the user and then change by $this->record, just trying to figure out how to run a query on the page and show the results in the table basically
Ah I see
so the query would be something like
You can chain the
query()
method on your table, quick example from the docs:
https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component#adding-the-tableI use a service for getting the query since its pretty complex is there a way I can use that in table builder?
What does the service return to you?
it returns a collections of Subjects that a user owns
Ah ok, so basically you can't use that with a Filament table, it's designed to work with a query builder
The workaround is to use Sushi, if you want to use a collection with a table
Filament
How to consume an external API with Filament Tables by Leandro Ferr...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
ok ill give that a go but just so I am clear for making custom pages
Do you need the render method since its already rendering the page or does the render method just load the table inside the parent template ?
You'll need to add
{{ $this->table }}
in the Blade viewwould that be in the view-votables.blade.php or would you make a custom make:livewire-table ?
gives me this error
Too few arguments to function App\Filament\Resources\UserResource\Pages\ViewVotables::table(), 0 passed in /var/www/html/vendor/filament/actions/src/Concerns/InteractsWithActions.php on line 308 and exactly 1 expected
Ah yeah, you'll need to implement
HasTable
as well, give this a quick review:
https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component#adding-the-tableahhh perfect thank you
@Patrick Boivin using sushi it looks like you need to create a custom model for it which is fine however how do you put a UserVotablesResource on a child of user/{record}/user-votable-resource
@datarecall Maybe this can help:
https://discord.com/channels/883083792112300104/1138671423586566184/1138853958501269566
The context is different but it shoud give you an idea of how to pass parameters to your query inside of getRows()
excellent I will take a look thank you @Patrick Boivin