Jun 30, 2025
9
Level 6
How to store notification in database using action?
I created a import action, I want to store the notification in database not just toast.
->headerActions([
Action::make('downloadTemplate')
->label('Download Template')
->icon('heroicon-m-arrow-down-tray')
->url('/members-template.xlsx')
->openUrlInNewTab()
->color('gray')
->outlined()
->tooltip('Template for importing members'),
Action::make('importMembers')
->label('Import Members')
->icon('heroicon-m-arrow-down-tray')
->color('success')
->form([
FileUpload::make('file')
->label('Excel File')
->acceptedFileTypes([
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel'
])
->helperText('Accepted formats: .xlsx, .xls or .csv ')
->required()
])
->action(function (array $data, $livewire, $action) {
$import = new MembersImport;
try {
Excel::import($import, $data['file']);
$recipient = auth()->user();
Notification::make()
->title('Import Complete')
->body("✅ Imported: {$import->successCount} members\n❌ Skipped: {$import->skippedCount} rows")
->success()
->sendToDatabase($recipient)
->send();
} catch (Throwable $e) {
$recipient = auth()->user();
Notification::make()
->title('Import Failed')
->body('Error: ' . $e->getMessage())
->danger()
->persistent()
->sendToDatabase($recipient)
->send();
}
})
])
Please or to participate in this conversation.