Is it possible to add actions to widgets?

I might be missing something, but I went throught the docs and couldnt find something.
12 Replies
DarkKnight
DarkKnightOP16mo ago
Maybe something like this?
Action::make('advance')
->action(fn (Contract $record) => $record->advance())
->modalContent(fn (Contract $record): View => view(
'filament.pages.actions.advance',
['record' => $record],
))
Action::make('advance')
->action(fn (Contract $record) => $record->advance())
->modalContent(fn (Contract $record): View => view(
'filament.pages.actions.advance',
['record' => $record],
))
DarkKnight
DarkKnightOP16mo ago
Then I have a white screen 😅
No description
DarkKnight
DarkKnightOP16mo ago
<x-filament-widgets::widget>
<x-filament::section>
<div>
@php
dd($action);
@endphp

</div>
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
<div>
@php
dd($action);
@endphp

</div>
</x-filament::section>
</x-filament-widgets::widget>
<?php

namespace App\Filament\Widgets;

use App\Models\User;
use Filament\Widgets\Widget;
use Filament\Actions\Action;
use Illuminate\Contracts\View\View;

class TestActionWidget extends Widget
{
protected static string $view = 'filament.widgets.test-action-widget';

public function deleteAction(): Action
{
return Action::make('test')
->registerModalActions([
Action::make('testAction')
->requiresConfirmation()
->action(fn (User $record) => $record->report()),
])
->action(fn (User $record) => $record->advance())
// ->requiresConfirmation()
->modalContent(fn (Action $action): View => view(
$view,
['action' => $action],
));
}
}
<?php

namespace App\Filament\Widgets;

use App\Models\User;
use Filament\Widgets\Widget;
use Filament\Actions\Action;
use Illuminate\Contracts\View\View;

class TestActionWidget extends Widget
{
protected static string $view = 'filament.widgets.test-action-widget';

public function deleteAction(): Action
{
return Action::make('test')
->registerModalActions([
Action::make('testAction')
->requiresConfirmation()
->action(fn (User $record) => $record->report()),
])
->action(fn (User $record) => $record->advance())
// ->requiresConfirmation()
->modalContent(fn (Action $action): View => view(
$view,
['action' => $action],
));
}
}
wyChoong
wyChoong16mo ago
Where you get these code? ChatGPT?
DarkKnight
DarkKnightOP16mo ago
No. Filament v3 docs Basically what I wanted to do is to have a widget in the Dashboard that has a specific action. I have found a workaround, and instead of creating an action for a widget I made one for Dashboard which is a livewire component. Then I added section in the blade file and called the action from there Like this:
<x-filament-panels::page>
<x-filament::section>
<div>
{{ $this->customAction }}

<x-filament-actions::modals />
</div>
</x-filament::section>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament::section>
<div>
{{ $this->customAction }}

<x-filament-actions::modals />
</div>
</x-filament::section>
</x-filament-panels::page>
wyChoong
wyChoong16mo ago
Why are you having dd?
DarkKnight
DarkKnightOP16mo ago
Because as mentioned I was getting a white screen, and I wanted to see what the value was
wyChoong
wyChoong16mo ago
Do you even understand php? That’s not how you access the $view in your code static::$view
DarkKnight
DarkKnightOP16mo ago
where is this supposed to be?
wyChoong
wyChoong16mo ago
When you copy and paste the code, read and try to understand it
DarkKnight
DarkKnightOP16mo ago
Yes I do... That method didnt work and I found a workaround
LordJoo
LordJoo6mo ago
what's the workaround ?

Did you find this page helpful?