F
Filament3w ago
Jon

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
awcodes
awcodes3w ago
->modifyQueryUsing() iirc
awcodes
awcodes3w ago
That’s with panels though. So you might need to override the base query if you’re just using the tables package.
Jon
JonOP3w ago
I am making progress if i use this line: 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.
awcodes
awcodes3w ago
Leave query(Hobby::query()) and use ->modifyQueryUsing() to add the with to the builder.
awcodes
awcodes3w ago
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
awcodes
awcodes3w ago
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.
Jon
JonOP3w ago
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};"]; })
No description
awcodes
awcodes3w ago
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.
awcodes
awcodes3w ago
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.
Jon
JonOP3w ago
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.
No description
awcodes
awcodes3w ago
I’m sure that would be possible without overriding the view.
Jon
JonOP3w ago
you are sure or not sure?
desired result:
No description
No description
awcodes
awcodes3w ago
I don’t know everything. 😂
Jon
JonOP3w ago
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.
awcodes
awcodes3w ago
Typo, should have been “wouldn’t”
Jon
JonOP3w ago
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
awcodes
awcodes3w ago
😂 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.
Jon
JonOP3w ago
sounds good wish i had money to build this thing for me... but i gotta learn it all myself
awcodes
awcodes3w ago
Only reason I’m where I am is because I learned it myself. Then people started paying for. Stay the course.
Want results from more Discord servers?
Add your server