How to change model to export from filament resource to exporter class

I have an application that uses filament 3.2 and in this application I have a resource called “Students”, within this resource I am calling a “TablesActionsExportBulkAction” that calls a custom exporter.

The problem is that my resource comes from the “Students” model and what I need to export is an entity called “Courses” which is another table and has a one to many relationship with students, so a course can have many students and a student can only belong to one course.

                TablesActionsExportBulkAction::make('export_courses')
                ->label('Courses export')
                ->icon('heroicon-o-document-arrow-down')
                ->color('success')
                ->modifyQueryUsing(function (Builder $query)
                {
                    $initalQuery = $query->pluck('id')->toArray();
                    $newQuery = Courses::query()
                        ->whereIn('student_id', $initalQuery)
                        ->with(['student', 'user']);
                    return $newQuery;
                })
                ->exporter(CoursesExporter::class),

But by default exporter takes the “Students” model that comes from the resource, and if I try to change it inside the exporter it doesn’t work:

protected static ?string $model = Courses::class;

I also tried to change the query inside the exporter using the “modifyQuery” method but it doesn’t work either, it gets an error when I try to export:

    public static function modifyQuery(Builder $query): Builder
{
    $initalQuery = $query->pluck('id')->toArray();
    $newQuery = Courses::query()
        ->whereIn('student_id', $initalQuery)
        ->with(['student', 'user']);
    return $newQuery;
}

Is there a way to do this natively with filament? Or maybe there’s a way to do this with a custom action or something?
I thank those who know and can respond!!

I’m using filament 3.2, php 8.2 and laravel 11.45.0