F
Filament12mo ago
Alfatic

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
ChesterS12mo 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
AlfaticOP12mo 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
ChesterS12mo ago
Do you have any resource files? Lile UserResource or something. But yeah, a global search would work too
Alfatic
AlfaticOP12mo ago
I have UserResource.php Is it located there?
ChesterS
ChesterS12mo ago
do you have CreateUser::route in there?
Alfatic
AlfaticOP12mo ago
I see function form, funcitn table
ChesterS
ChesterS12mo ago
sorry, i mean ListUsers
Alfatic
AlfaticOP12mo ago
Yeah, in funciton getPages in a returned array
ChesterS
ChesterS12mo ago
ok click on it - it should take you to the ListUsers.php file
Alfatic
AlfaticOP12mo ago
return [ 'index' => Pages\ListUsers::route('/'), etc.
ChesterS
ChesterS12mo ago
yep, go to that class
Alfatic
AlfaticOP12mo ago
ok i am in
ChesterS
ChesterS12mo ago
do you have the following?
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
Alfatic
AlfaticOP12mo ago
yes i see that
ChesterS
ChesterS12mo ago
ok, that's where you update your notification for when you create a user
Alfatic
AlfaticOP12mo 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
ChesterS12mo ago
You can do that there too. Just override the getCreatedNotificationTitle() method
Alfatic
AlfaticOP12mo ago
Now, the problem where to put the code
ChesterS
ChesterS12mo ago
Which code?
Alfatic
AlfaticOP12mo ago
let's go back to listusers.php CreateAction::make() ->successNotificationTitle('User registered')
ChesterS
ChesterS12mo ago
Ok, it's already there. You just need to add the method that's missing
Alfatic
AlfaticOP12mo ago
Oh, that arrow
ChesterS
ChesterS12mo 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
AlfaticOP12mo ago
and what follows
ChesterS
ChesterS12mo ago
yeap this is just a method call Did it work as expected?
Alfatic
AlfaticOP12mo 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
ChesterS12mo 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
ChesterS12mo 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
AlfaticOP12mo ago
YEAH!!!! it's working!!!
ChesterS
ChesterS12mo ago
Cool. Have a look at the CreateRecord , EditRecord etc classes for more things you can do Good luck
Alfatic
AlfaticOP12mo 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
ChesterS12mo 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.
Want results from more Discord servers?
Add your server