how do I add ->with statements to the table query?
ALl the query related things in the docs seem to be to adjust individual columns.
if i need to add ->withCount($this->getDemographics())
to the table data, to handle the following set up, where do i add this?
21 Replies
->modifyQueryUsing() iirc
That’s with panels though. So you might need to override the base query if you’re just using the tables package.
I am making progress if i use this line:
the as __ part is not working.
I am not sure what needs to be adjusted within filament.
public static function table(Table $table): Table
{
return $table
->query(Hobby::with(self::getDemographics()))
->columns([...
when i made the function static, but now i get an error "Call to undefined relationship [users as m_count] on model [Modules\Hobbies\Models\Hobby]."
and ill assume all other demographic designations.the as __ part is not working.
I am not sure what needs to be adjusted within filament.
Leave query(Hobby::query()) and use ->modifyQueryUsing() to add the with to the builder.
GitHub
filament/packages/tables/src/Table/Concerns/HasQuery.php at 3.x · f...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
I swear it was in the docs, just can’t find it right now. It’s essentially the same as using it in filters, except it’s at the table level allowing filters to still be applied.
It follows the builder pattern.
it appears to be working...
->modifyQueryUsing(fn(Builder $query
) => $query->withCount(self::getDemographics()))
(i dont fully understand the Builder pattern, or exactly how Filament gets the data. )
I also found a way to stylize individual columns to add some separation: (but I did not see this information in the docs for tables other than in TESTING)
->extraAttributes(function (?Hobby $record) {
$bgColor = '#5cbbc180';
return ['style' => "background-color: {$bgColor};"];
})Yea. Typically with that level of styling you would want to add classes to the row so you can style them with tailwind and a custom theme.
But as always. Multiple ways to achieve the same outcome.
In laravel calling Model::query() returns an instance of the query builder meaning you can chain methods onto it before ultimately calling ->get() or ->paginate() etc to actually retrieve the records.
I did end up using this instead:
->extraAttributes(function (?Hobby $record) {
$bgColorClass
= 'bg-teal-700 border-l-4 border-blue-900';
return ['class' => $bgColorClass];
})
If i want to get fancy and highlight the higher percentage of each row... I suppose I could use the ->recordClasses(fn (Model $record) => match ($record->status) set up?
though not sure if this can compare with other column values.
Im not going to worry about that right now.
However, if I want to move the tabs down to be in the same row as the search bar (still centered), I think I would use "TablesRenderHook::TOOLBAR_SEARCH_BEFORE", Though I'm not sure which file or function to put it in or how to include the tabs.
I’m sure that would be possible without overriding the view.
you are sure or not sure?
desired result:
desired result:
I don’t know everything. 😂
thats alright. But you said you were sure... im going to assume typo.
no biggy. Thanks for the help, ive been wondering abuot that issue for a while.
Typo, should have been “wouldn’t”
figured. Again, thanks anyway, I've got the functionality down. Ill try to make it look pretty later
so much left to do
how much does it cost to hire you all
😂 I think Zep is the only one currently doing consulting. https://filamentphp.com/consulting
Filament
Consulting - Filament
Looking for dedicated help with your Filament project? Contact the experts who built Filament.
sounds good
wish i had money to build this thing for me... but i gotta learn it all myself
Only reason I’m where I am is because I learned it myself. Then people started paying for. Stay the course.