Send a simple email after a resource is created
Hi all, I am new to the laravel and filament community and I have managed to create a new notification php artisan make:notification TicketCreatedNotification
How do I send this notification after a new Ticket resource is created.
Looking online they refer to Filament methods afterCreate() and afterSave(), but when I try and implement these suggestions I get an error that the methods do not exist,
For example:
public static function form(Form $form): Form
{
return $form
->schema([
// ... your fields
])
->afterCreate(function ($record, $data) {
$record->notify(new TicketCreatedNotification($record));
});
}
How do I send this notification after a new Ticket resource is created.
Looking online they refer to Filament methods afterCreate() and afterSave(), but when I try and implement these suggestions I get an error that the methods do not exist,
For example:
public static function form(Form $form): Form
{
return $form
->schema([
// ... your fields
])
->afterCreate(function ($record, $data) {
$record->notify(new TicketCreatedNotification($record));
});
}
Solution
Could you link your notification to a Laravel Model Event? For example, whenever a model is created, fire off the Notification?
https://laravel.com/docs/10.x/eloquent#events
https://laravel.com/docs/10.x/eloquent#events
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
