Open btxtiger opened 1 day ago
Hey @btxtiger! We're sorry to hear that you've hit this issue. π
However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?
We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.
Thank you for providing reproduction steps! Reopening the issue now.
i think you should use formatStateUsing instead of getStateUsing()
@Cybrarist this does not work, since the state of the column should be any query or value (probably also a result of an HTTP request, Cache, other service, ...), and not dependant on a model column.
@btxtiger oh ok, i get what you mean, then why not doing it like the following
$table->modifyQueryUsing(function (Builder $query) {
$query->withCount('permissions');
})
and then you use 'permissions_count' in your TextColumn.
@Cybrarist yes this would be a workaround for this specific example, but would not solve the actual problem. Let me show you a different example:
Tables\Columns\TextColumn::make('permission_granted')
->label('Permissions')
->badge()
->getStateUsing(function (User $user) {
return Http::get('https://dummy-auth-provider.com/api/check-permissions', ['uuid' => $user->uuid])
->json('permissions_granted') ? 'Granted' : 'Not Granted';
});
In this case, the closure is still executed 3 times, and thus make 3 https requests * number of rows, for 1 page load
Package
filament/tables
Package Version
v3.2.124
Laravel Version
v11.33.2
Livewire Version
default
PHP Version
8.3.13
Problem description
When using
->getStateUsing()
to fill a column with a custom value, the Closure seems to be called 3 times per row!If this closure contains a custom query, this will lead to triple query execution per row!
Expected behavior
The Closure should be executed once on page load
Steps to reproduce
Example Column:
Reproduction repository (issue will be closed if this is not valid)
https://github.com/btxtiger/filament-getstateusing-bug-14852
Relevant log output
No response
Donate π° to fund this issue