Arjen
Arjen
FFilament
Created by Arjen on 4/9/2025 in #❓┊help
Dynamic ExportColumns based on JSON field in Exporter, possible?
class CourseRegistrationExporter extends Exporter
{
protected static ?string $model = CourseRegistration::class;

public static function getColumnsBefore(): array
{
return [
ExportColumn::make('id')
->label('ID'),
// More columns...
];
}

public static function getColumnsAfter(): array
{
return [
// More columns...
ExportColumn::make('created_at')
->label('Datum aanmelding'),
];
}

public static function getExtraColumns($id): array
{
$extraColumns = [];
$course = Course::find($id);
if ($course && $course->extra_fields) {
foreach ($course->extra_fields as $field) {
$label = $field['data']['label'];
$extraColumns[] = ExportColumn::make('extra_fields.'.$label)
->label($label);
}
}

return $extraColumns;
}

public static function getColumns(): array
{
return [
...static::getColumnsBefore(),
...static::getExtraColumns(session('export_parent_record_id')),
...static::getColumnsAfter(),
];
}

public function getColumnsForJob(): array
{
return [
...static::getColumnsBefore(),
...static::getExtraColumns(data_get($this->getOptions(), 'export_parent_record_id', null)),
...static::getColumnsAfter(),
];
}

/**
* @return array<ExportColumn>
*/
public function getCachedColumns(): array
{
return $this->cachedColumns ??= array_reduce($this->getColumnsForJob(), function (array $carry, ExportColumn $column): array {
$carry[$column->getName()] = $column->exporter($this);

return $carry;
}, []);
}
}
class CourseRegistrationExporter extends Exporter
{
protected static ?string $model = CourseRegistration::class;

public static function getColumnsBefore(): array
{
return [
ExportColumn::make('id')
->label('ID'),
// More columns...
];
}

public static function getColumnsAfter(): array
{
return [
// More columns...
ExportColumn::make('created_at')
->label('Datum aanmelding'),
];
}

public static function getExtraColumns($id): array
{
$extraColumns = [];
$course = Course::find($id);
if ($course && $course->extra_fields) {
foreach ($course->extra_fields as $field) {
$label = $field['data']['label'];
$extraColumns[] = ExportColumn::make('extra_fields.'.$label)
->label($label);
}
}

return $extraColumns;
}

public static function getColumns(): array
{
return [
...static::getColumnsBefore(),
...static::getExtraColumns(session('export_parent_record_id')),
...static::getColumnsAfter(),
];
}

public function getColumnsForJob(): array
{
return [
...static::getColumnsBefore(),
...static::getExtraColumns(data_get($this->getOptions(), 'export_parent_record_id', null)),
...static::getColumnsAfter(),
];
}

/**
* @return array<ExportColumn>
*/
public function getCachedColumns(): array
{
return $this->cachedColumns ??= array_reduce($this->getColumnsForJob(), function (array $carry, ExportColumn $column): array {
$carry[$column->getName()] = $column->exporter($this);

return $carry;
}, []);
}
}
6 replies
FFilament
Created by Arjen on 4/9/2025 in #❓┊help
Dynamic ExportColumns based on JSON field in Exporter, possible?
I found a workaround that works for my use case. I added the ID to the ExportAction->options([]) array and I've overridden the getCachedColumns method to not get the columns from the static getColumns method, but from a different method that can read the options. I've kept the session from before, because you can't read the non-static options in the static getColumns method.
Tables\Actions\ExportAction::make()
->exporter(CourseRegistrationExporter::class)
->beforeFormFilled(function () {
// Used for the column mapping form.
session(['export_parent_record_id' => $this->getOwnerRecord()->id]);
})
->options([
// Used when exporting (no access to session).
'export_parent_record_id' => $this->getOwnerRecord()->id,
])
Tables\Actions\ExportAction::make()
->exporter(CourseRegistrationExporter::class)
->beforeFormFilled(function () {
// Used for the column mapping form.
session(['export_parent_record_id' => $this->getOwnerRecord()->id]);
})
->options([
// Used when exporting (no access to session).
'export_parent_record_id' => $this->getOwnerRecord()->id,
])
6 replies
FFilament
Created by Arjen on 4/9/2025 in #❓┊help
Dynamic ExportColumns based on JSON field in Exporter, possible?
I've now tried using sessions, but that didn't work because the export job doesn't use the current session. It worked when mapping the columns.
Tables\Actions\ExportAction::make()
->beforeFormFilled(function () {
session(['export_parent_record_id' => $this->getOwnerRecord()->id]);
})
->exporter(CourseRegistrationExporter::class);

// CourseRegistrationExporter::class
public static function getColumns(): array
{
session('export_parent_record_id');

return [
// ExportColumns
];
}
Tables\Actions\ExportAction::make()
->beforeFormFilled(function () {
session(['export_parent_record_id' => $this->getOwnerRecord()->id]);
})
->exporter(CourseRegistrationExporter::class);

// CourseRegistrationExporter::class
public static function getColumns(): array
{
session('export_parent_record_id');

return [
// ExportColumns
];
}
6 replies
FFilament
Created by Arjen on 3/31/2025 in #❓┊help
GRecaptcha field disappears on livewire/update in a Livewire Component, but not in Panel Resource
I've figured it out, I had moved the app script in @vite to before the body, when I moved it back to the head, it works as it should. Wrong:
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
{{-- // --}}
@filamentStyles
@vite(['resources/css/filament/platform/theme.css', 'resources/css/app.css'])
</head>

<body>
{{-- // --}}
@filamentScripts
@vite('resources/js/app.js')
</body>

</html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
{{-- // --}}
@filamentStyles
@vite(['resources/css/filament/platform/theme.css', 'resources/css/app.css'])
</head>

<body>
{{-- // --}}
@filamentScripts
@vite('resources/js/app.js')
</body>

</html>
Good:
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
{{-- // --}}
@filamentStyles
@vite(['resources/css/filament/platform/theme.css', 'resources/css/app.css', 'resources/js/app.js'])
</head>

<body>
{{-- // --}}
@filamentScripts
</body>
</html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
{{-- // --}}
@filamentStyles
@vite(['resources/css/filament/platform/theme.css', 'resources/css/app.css', 'resources/js/app.js'])
</head>

<body>
{{-- // --}}
@filamentScripts
</body>
</html>
6 replies
FFilament
Created by Arjen on 3/31/2025 in #❓┊help
GRecaptcha field disappears on livewire/update in a Livewire Component, but not in Panel Resource
That sadly wasn't the issue. I had that before in my class, but I wrongfully omitted it in the example.
6 replies
FFilament
Created by Arjen on 3/30/2025 in #❓┊help
How to get infolist in ViewAction modal in table widget?
I am, I was hoping/expecting that Action to just work, but it seems it doens't hehe
6 replies
FFilament
Created by Arjen on 3/18/2025 in #❓┊help
Form with Wizard not saving relations with non-default statePaths
Previous file continued:
public function submit(): void
{
DB::transaction(function () {
$data = $this->form->getState();
// Creating user and organization with data.organization and data.user first...
$service = Models\Service::create($data['data']['service']);
$this->form->model($service)->statePath('data.service')->saveRelationships(); // This does not work, even without ->statePath()...
});
}
}
public function submit(): void
{
DB::transaction(function () {
$data = $this->form->getState();
// Creating user and organization with data.organization and data.user first...
$service = Models\Service::create($data['data']['service']);
$this->form->model($service)->statePath('data.service')->saveRelationships(); // This does not work, even without ->statePath()...
});
}
}
The data retrieved in the submit method looks like this:
$data = [
'data' => [
'user' => [...],
'organization' => [...],
'service' => [...],
],
];
$data = [
'data' => [
'user' => [...],
'organization' => [...],
'service' => [...],
],
];
I can't get the selected categories saved in the $service record I created. Any idea what I'm doing wrong? The categories relationship is many to many. I also have a normal ServiceResource in my panel where the categories checkboxlist works as it should, however without any changes to the statePath.
3 replies
FFilament
Created by Arjen on 2/20/2025 in #❓┊help
Get current row in castStateUsing ImportColumn
Solved with:
->castStateUsing(function (?string $state, Importer $importer) {
// $importer->getData()['ID']...
return $state;
}),
->castStateUsing(function (?string $state, Importer $importer) {
// $importer->getData()['ID']...
return $state;
}),
4 replies
FFilament
Created by Arjen on 3/10/2025 in #❓┊help
Different configuration for Actions inside ActionGroup possible?
Solved with:
ActionGroup::configureUsing(function (ActionGroup $actionGroup) {
$actions = $actionGroup->getActions();
foreach ($actions as $action) {
$action->grouped();
}
});
ActionGroup::configureUsing(function (ActionGroup $actionGroup) {
$actions = $actionGroup->getActions();
foreach ($actions as $action) {
$action->grouped();
}
});
4 replies
FFilament
Created by Arjen on 2/12/2025 in #❓┊help
Change table columns/filters based on active tab?
Thanks!
6 replies
FFilament
Created by Arjen on 1/27/2025 in #❓┊help
Wizard loses $_GET param after next step
This works, thanks! Had to change protected to public.
5 replies
FFilament
Created by Arjen on 1/25/2024 in #❓┊help
Table column loses data when sorting by relationship
I've got it working by using the following code:
Tables\Columns\TextColumn::make('booking_date')
->label('Datum')
->date('d-m-Y')
->sortable(
query: fn ($query, $direction) => $query
->join('dayparts', function ($join) {
$join->on('dayparts.booking_id', '=', 'bookings.id')
->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
})
->orderBy('date', $direction)
),
Tables\Columns\TextColumn::make('booking_date')
->label('Datum')
->date('d-m-Y')
->sortable(
query: fn ($query, $direction) => $query
->join('dayparts', function ($join) {
$join->on('dayparts.booking_id', '=', 'bookings.id')
->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
})
->orderBy('date', $direction)
),
Booking model:
public function getBookingDateAttribute()
{
return data_get($this, 'date', data_get($this->dayparts, '0.date', null));
}
public function getBookingDateAttribute()
{
return data_get($this, 'date', data_get($this->dayparts, '0.date', null));
}
I'm curious to know if this is an acceptable solution or if there are better solutions for this problem.
3 replies
FFilament
Created by Arjen on 12/1/2023 in #❓┊help
Convert Filament::registerScripts
@giuseppemastrodonato Sadly no.
5 replies
FFilament
Created by Arjen on 10/11/2023 in #❓┊help
Setting searchable select field to null not working
That didn't work either. When I click the x in the select field, it shows nothing. With null it at least shows the placeholder. But I shouldn't have to press the x.
4 replies
FFilament
Created by Arjen on 9/30/2023 in #❓┊help
Best way to include script
Ooh nice one, thanks!
5 replies
FFilament
Created by Arjen on 9/30/2023 in #❓┊help
Best way to include script
... so I'm not sure if this is the correct way to include scripts that I want to have loaded on all pages
5 replies
FFilament
Created by Arjen on 3/9/2023 in #❓┊help
Error when prefilling from query string in resource with persistTabInQueryString enabled
Sure!
11 replies
FFilament
Created by Arjen on 3/9/2023 in #❓┊help
Error when prefilling from query string in resource with persistTabInQueryString enabled
Tried it that way but it's still not working. It seems like a bug in Filament. @Dan Harrin Any thoughts about it? Should I make an issue in the github repo?
11 replies
FFilament
Created by Arjen on 3/9/2023 in #❓┊help
Error when prefilling from query string in resource with persistTabInQueryString enabled
I don't understand what validation rules have to with my problem. My query string gets validated fine, but I get a Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization when have the following enabled: ->persistTabInQueryString('tab')
11 replies
FFilament
Created by Arjen on 3/9/2023 in #❓┊help
Error when prefilling from query string in resource with persistTabInQueryString enabled
Not sure what you mean by rules()
11 replies