Array of actions on a custom page - Not possible ?

Hi guys, I'm trying to make a custom export page that display some Filament actions dynamically but it's not working. Is there a way do to that or it's not possible and I must declare one method per action, as explained in the docs (https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#adding-the-action).
<?php

declare(strict_types=1);

namespace App\Filament\Pages;

use App\Exports\HourlyWageExport;
use App\Exports\UserExport;
use App\Filament\Actions\Exports\UserMensualAdminExportAction;
use App\Filament\Actions\SimpleExportAction;
use Filament\Actions\Action;
use Filament\Pages\Page;

class Exports extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-arrow-down-on-square-stack';

protected static string $view = 'filament.pages.exports';

/**
* @return array<string, array<int, Action>>
*/
public function actions(): array
{
return [
'Généraux' => [
SimpleExportAction::action(new UserExport, 'users-export')
->label('Utilisateurs'),
SimpleExportAction::action(new HourlyWageExport, 'hourly-wage-export')
->label('Salaires horaires'),
],
'Team Admin' => [
UserMensualAdminExportAction::make(),
],
'Team RC' => [],
];
}
}
<?php

declare(strict_types=1);

namespace App\Filament\Pages;

use App\Exports\HourlyWageExport;
use App\Exports\UserExport;
use App\Filament\Actions\Exports\UserMensualAdminExportAction;
use App\Filament\Actions\SimpleExportAction;
use Filament\Actions\Action;
use Filament\Pages\Page;

class Exports extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-arrow-down-on-square-stack';

protected static string $view = 'filament.pages.exports';

/**
* @return array<string, array<int, Action>>
*/
public function actions(): array
{
return [
'Généraux' => [
SimpleExportAction::action(new UserExport, 'users-export')
->label('Utilisateurs'),
SimpleExportAction::action(new HourlyWageExport, 'hourly-wage-export')
->label('Salaires horaires'),
],
'Team Admin' => [
UserMensualAdminExportAction::make(),
],
'Team RC' => [],
];
}
}
No description
5 Replies
Benjamin
BenjaminOP7d ago
<?php

use App\Filament\Pages\Exports;

/** @var Exports $this */
?>

<x-filament-panels::page>

<div class="grid grid-cols-12 gap-12">
<?php foreach ($this->actions() as $title => $actions) { ?>
<x-filament::section class="col-span-4">
<x-slot name="heading">
<?= $title ?>
</x-slot>

<div class="flex flex-col gap-4">
<?php foreach ($actions as $action) { ?>
{{ $action }}
<?php } ?>
</div>
</x-filament::section>
<?php } ?>
</div>

</x-filament-panels::page>
<?php

use App\Filament\Pages\Exports;

/** @var Exports $this */
?>

<x-filament-panels::page>

<div class="grid grid-cols-12 gap-12">
<?php foreach ($this->actions() as $title => $actions) { ?>
<x-filament::section class="col-span-4">
<x-slot name="heading">
<?= $title ?>
</x-slot>

<div class="flex flex-col gap-4">
<?php foreach ($actions as $action) { ?>
{{ $action }}
<?php } ?>
</div>
</x-filament::section>
<?php } ?>
</div>

</x-filament-panels::page>
toeknee
toeknee7d ago
You have not included the modals component in the lade as per the acitons docs
toeknee
toeknee7d ago
https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component You also need <x-filament-actions::modals /> which injects the HTML required to render action modals. This only needs to be included within the Livewire component once, regardless of how many actions you have for that component.
Benjamin
BenjaminOP7d ago
I tried and it's not working either (I think it's not required if the page lives in a Filament panel). When I click, the action is loading for a few seconds, then it stops and nothing happen.
toeknee
toeknee7d ago
Possibly actually. That's usually when somehting hasn't worked

Did you find this page helpful?