In which file should I put customized toast notification?

I want a custom message to pop in the "toast" little info window when an item is created. However, I don't know where to put it, in which file. Again, this is something I struggle a lot with in Filament and I think this could be improved by providing perhaps more real world examples with real files with real names - just an idea. Anyway, I have found this https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create and https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#customizing-the-save-notification but I don't know where to put this code:
CreateAction::make()
->successNotificationTitle('Bingo! User created!')
CreateAction::make()
->successNotificationTitle('Bingo! User created!')
I am using the standard resource and it is happening in CreateUser.php? I am not sure. Thanks for any advice where to put that code.
Solution:
so the end result should look something like ```php class CreateUser extends CreateRecord {...
Jump to solution
32 Replies
ChesterS
ChesterS7mo ago
I understand your frustration but you must accept that there will be a learning curve with anything new. You'll need time to get familiar with all the conventions used with Filament - it's an opiniated framework, like Laravel. Plus, you can always update the documentation if you think something is missing or not clear enough. Back to your question, do you have CreateAction anywhere in your code?
Alfatic
Alfatic7mo ago
I want to bind that action to the save button I am not sure where to look for it, should I try some global search in PhpStorm?
ChesterS
ChesterS7mo ago
Do you have any resource files? Lile UserResource or something. But yeah, a global search would work too
Alfatic
Alfatic7mo ago
I have UserResource.php Is it located there?
ChesterS
ChesterS7mo ago
do you have CreateUser::route in there?
Alfatic
Alfatic7mo ago
I see function form, funcitn table
ChesterS
ChesterS7mo ago
sorry, i mean ListUsers
Alfatic
Alfatic7mo ago
Yeah, in funciton getPages in a returned array
ChesterS
ChesterS7mo ago
ok click on it - it should take you to the ListUsers.php file
Alfatic
Alfatic7mo ago
return [ 'index' => Pages\ListUsers::route('/'), etc.
ChesterS
ChesterS7mo ago
yep, go to that class
Alfatic
Alfatic7mo ago
ok i am in
ChesterS
ChesterS7mo ago
do you have the following?
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
Alfatic
Alfatic7mo ago
yes i see that
ChesterS
ChesterS7mo ago
ok, that's where you update your notification for when you create a user
Alfatic
Alfatic7mo ago
hmm why not in CreateUser.php? or EditUser.php? What if I create another page PasswordEdit.php and would like to have another toast just for that page with different action buttons
ChesterS
ChesterS7mo ago
You can do that there too. Just override the getCreatedNotificationTitle() method
Alfatic
Alfatic7mo ago
Now, the problem where to put the code
ChesterS
ChesterS7mo ago
Which code?
Alfatic
Alfatic7mo ago
let's go back to listusers.php CreateAction::make() ->successNotificationTitle('User registered')
ChesterS
ChesterS7mo ago
Ok, it's already there. You just need to add the method that's missing
Alfatic
Alfatic7mo ago
Oh, that arrow
ChesterS
ChesterS7mo ago
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->successNotificationTitle('User registered'), // <- This
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->successNotificationTitle('User registered'), // <- This
];
}
Alfatic
Alfatic7mo ago
and what follows
ChesterS
ChesterS7mo ago
yeap this is just a method call Did it work as expected?
Alfatic
Alfatic7mo ago
hmm, it's not working for the getHeaderActions for some reason Oh, wait No it says created and then it's empty I have to probably setup something somewhere. thanks anyway --- Is there a youtube tutorial somewhere? how to set up a customized toast in Filament?
ChesterS
ChesterS7mo ago
in that case, you might need to override it in the method in CreateUser Go to the CreateUser class and add the following method
protected function getCreatedNotificationTitle() : ?string{
return 'Bingo! User created';
}
protected function getCreatedNotificationTitle() : ?string{
return 'Bingo! User created';
}
Solution
ChesterS
ChesterS7mo ago
so the end result should look something like
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

protected function getCreatedNotificationTitle() : ?string {
return 'Bingo! User created';
}
}
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

protected function getCreatedNotificationTitle() : ?string {
return 'Bingo! User created';
}
}
Alfatic
Alfatic7mo ago
YEAH!!!! it's working!!!
ChesterS
ChesterS7mo ago
Cool. Have a look at the CreateRecord , EditRecord etc classes for more things you can do Good luck
Alfatic
Alfatic7mo ago
OK, I am reading and rereading the docs, so, it's getting clearer every hour, but it's still somehow confusing. But it's getting better. And I think after a month or two, Filament could be really powerful and you can create new Laravel projects very quickly.
ChesterS
ChesterS7mo ago
Yeap, that's the point. As I said there is a learning curve but you can do some cool stuff once you're familiar.