Nijholt
Nijholt
FFilament
Created by Nijholt on 2/21/2025 in #❓┊help
Retrieve data from a custom Filament\Actions\Action
In my action I've got a custom view:
<x-filament::dropdown.list>
@foreach ($getOptions() as $key => $item)
@php
$wireClickAction = "mountAction('{$action->getName()}', { id: 12345 })";
@endphp
<x-filament::dropdown.list.item wire:click="{{ $wireClickAction }}" wire:key="{{ $key }}">
<x-filament::badge :color="$item->getColor()">
{{ $item->getLabel() }}
</x-filament::badge>
</x-filament::dropdown.list.item>
@endforeach
</x-filament::dropdown.list>
<x-filament::dropdown.list>
@foreach ($getOptions() as $key => $item)
@php
$wireClickAction = "mountAction('{$action->getName()}', { id: 12345 })";
@endphp
<x-filament::dropdown.list.item wire:click="{{ $wireClickAction }}" wire:key="{{ $key }}">
<x-filament::badge :color="$item->getColor()">
{{ $item->getLabel() }}
</x-filament::badge>
</x-filament::dropdown.list.item>
@endforeach
</x-filament::dropdown.list>
Now when clicking on a list item the action gets triggered, but $data remains empty:
PublicationStatusAction::make('status')
->action(function ($data): void {
dd($data);
})
PublicationStatusAction::make('status')
->action(function ($data): void {
dd($data);
})
result: []
5 replies
FFilament
Created by Nijholt on 2/19/2025 in #❓┊help
HeaderAction disappears after usage.
I've got this action:
<?php

declare(strict_types=1);

namespace App\Filament\Components\HeaderActions;

use App\Models\Status;
use Filament\Actions\Action;

class PublicationStatusAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this
->view('filament.actions.publication-status')
->hidden(false);
}

public static function make(?string $name = null): static
{
return parent::make($name);
}

public function getOptions(): array
{
return [
'published' => __('status_action.' . Status::STATUS_PUBLISHED),
'unpublished' => __('status_action.' . Status::STATUS_UNPUBLISHED),
];
}

public function getSelected(): string
{
return $this->getRecord()->status?->key ?? '';
}
}
<?php

declare(strict_types=1);

namespace App\Filament\Components\HeaderActions;

use App\Models\Status;
use Filament\Actions\Action;

class PublicationStatusAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this
->view('filament.actions.publication-status')
->hidden(false);
}

public static function make(?string $name = null): static
{
return parent::make($name);
}

public function getOptions(): array
{
return [
'published' => __('status_action.' . Status::STATUS_PUBLISHED),
'unpublished' => __('status_action.' . Status::STATUS_UNPUBLISHED),
];
}

public function getSelected(): string
{
return $this->getRecord()->status?->key ?? '';
}
}
With view:
<x-filament::input.wrapper>
<x-filament::input.select
x-on:change="$wire.updateStatus($event.target.value)"
class="fi-select-input"
>
@foreach ($getOptions() as $value => $label)
<option value="{{ $value }}" @if ($value === $getSelected()) selected @endif>
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
<x-filament::input.wrapper>
<x-filament::input.select
x-on:change="$wire.updateStatus($event.target.value)"
class="fi-select-input"
>
@foreach ($getOptions() as $value => $label)
<option value="{{ $value }}" @if ($value === $getSelected()) selected @endif>
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
Code works, but after change, the components gets detached. How to prevent the action from disappearing from the header actions?
7 replies