Issue with Table Joins in Exports

Hi everyone, I'm encountering an issue when working with Filament's modifyQuery method for Exports. Specifically, when I try to include table joins or additional query logic (e.g., grouping or calculated columns), the export doesn’t seem to reflect the expected data. Here’s an example of my modifyQuery implementation:
public static function modifyQuery(Builder $query): Builder
{
return $query
->select('holds.*', 'users.name as created_by_name') // Include basic fields from the hold and joined user
->leftJoin('users', 'users.id', '=', 'holds.created_by_id'); // Simple join to get the creator's name
}
public static function modifyQuery(Builder $query): Builder
{
return $query
->select('holds.*', 'users.name as created_by_name') // Include basic fields from the hold and joined user
->leftJoin('users', 'users.id', '=', 'holds.created_by_id'); // Simple join to get the creator's name
}
I’ve added the column to the export like this:
ExportColumn::make('created_by_name');
ExportColumn::make('created_by_name');
But when I export, the created_by_name column isn’t filled at all. For additional debugging, I added the following:
ExportColumn::make('created_by_name')
->getStateUsing(function ($record) {
ray($record);
});
ExportColumn::make('created_by_name')
->getStateUsing(function ($record) {
ray($record);
});
What I noticed:
- The $record object only includes data directly from the model/table (e.g., holds), and none of the computed or joined columns (created_by_name) are present.
- It seems like the export is only pulling fields defined in the model, ignoring any additional columns from the query.
Context: - The same logic works perfectly in a Resource table using getEloquentQuery, although this doesn't transfer to the export. - It seems that the modifyQuery method doesn’t affect what data is passed to the export columns.
Does anyone know if there’s a limitation in how modifyQuery interacts with exports? Or am I missing something about how to include computed/joined columns in export data?
I’d appreciate any advice or insight on how to resolve this!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server