Problem: Exporter Not Working with Eager-Loaded Relationships
I’m trying to use a TitleExporter to export data from my Title model. Here’s the code for my exporter:
<?php
namespace App\Filament\Exports;
use App\Models\Title;
use Carbon\CarbonInterface;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class TitleExporter extends Exporter
{
protected static ?string $model = Title::class;
public static function getColumns(): array
{
return [
ExportColumn::make('id')->label('Id'),
ExportColumn::make('name')->label('Name'),
ExportColumn::make('created_at')->label('Created at'),
ExportColumn::make('updated_at')->label('Updated at'),
];
}
}
The Title model is configured to eagerly load some relationships using the protected $with property:
protected $with = ['metadata', 'metadata.parent', 'metadata.parent.metadata'];
In the table, everything works perfectly: the metadata relationships are fetched and displayed without issues.
However, when I try to export, I get the following error:
Call to undefined relationship [metadata] on model [App\Models\Metadata].
It seems like the exporter isn’t able to handle the relationships defined in the $with property. Does anyone know why this might be happening or how I can fix it? Any advice is much appreciated! Thanks!0 Replies