class HeaderActions extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;
public function render()
{
return view('livewire.header-actions');
}
public function deleteAction(): Action
{
return Action::make('delete 2')
->requiresConfirmation()
->action(fn () => dd('delete user'));
}
public function cacheAction(): Action
{
return Action::make('Flush Cache')
->action(function (): void {
$this->flushCache();
})
->label('Flush Cache')
->requiresConfirmation()
->modalHeading('Flush Cache')
->modalDescription('Are you sure you want to flush the cache? This will clear all cached data.')
->modalSubmitActionLabel('Flush Cache');
}
public function flushSessionsAction(): Action
{
return Action::make('Flush Sessions')
->action(function (): void {
$this->flushSessions();
})
->requiresConfirmation()
->label('Flush Sessions')
->modalHeading('Flush Sessions')
->modalDescription('Are you sure you want to flush all sessions?')
->modalSubmitActionLabel('Flush Sessions');
}
protected function flushCache(): void
{
Redis::connection()->flushdb();
Notification::make()
->title('Cache Flushed')
->body('Cache has been flushed successfully.')
->success()
->send();
// Redirect to the dashboard
return redirect()->route('dashboard');
}
protected function flushSessions(): void
{
Redis::connection()->flushdb();
Notification::make()
->title('Sessions Flushed')
->body('Sessions have been flushed successfully.')
->success()
->send();
}
}