Export action to display data from relationships

Hi.. I have follow the documentation to display data from relation for the Export action (https://filamentphp.com/docs/3.x/actions/prebuilt-actions/export#displaying-data-from-relationships).

The problem is whe I use ExportColumn::make('gender.name'), the relation value is not showing.

but if I just use the gender relationship ExportColumn::make('gender') the whole relation value are show {"id":2,"name":"Female","created_at":"2024-02-08T04:18:13.000000Z","updated_at":"2024-02-08T04:18:13.000000Z","deleted_at":null}

I'm using filament 3.2. Here is my code. What is missing here?

UserExporter.php

namespace App\Filament\Exports;

use App\Models\User;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;

class UserExporter extends Exporter
{
    protected static ?string $model = User::class;

    public static function getColumns(): array
    {
        return [
            ExportColumn::make('id')
                ->label('ID'),
            ExportColumn::make('name'),
            ExportColumn::make('email'),
            ExportColumn::make('gender'),
            // ExportColumn::make('gender.name'),
        ];
    }
}



User.php

public function gender(): BelongsTo
{
    return $this->belongsTo(gender::class,'gender_id');
}


Gender.php

class Gender extends Model
{
    use HasFactory, SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];

    public function users(): HasMany
    {
        return $this->hasMany(User::class);
    }
}

I'm using filament 3.2. Here is my code. What is missing here?
image.png
Solution
Have you tried updating Filament to latest version? There was a bug in early versions of 3.2 which caused relation data not to show up in export at all.
Was this page helpful?