Notifications
Guys, have you ever had a problem with notifications?
I'm making an insertion in my customers table and I needed a notification to be displayed when registered.
Registration takes place through an end-point on a route that I created to receive an external request.
Reading the documentation I saw databaseNotifications.
There in my AdminPanelProvider I placed the property:
->databaseNotifications();
So far, it was a great show, it ran smoothly and appeared on the panel.
Then I ran the notification migration, everything was fine too.
I created a CustomerObserver observer, and in the creation function I did:
Also, in my EventServiceProvider in the method:
I made this modification.
However, despite everything, the notification was not registered in the bd nor displayed.
35 Replies
Please read our #✅┊rules and format your code propely
Sorry
You are sending the notification to the customer that was created. Is this intentional?
->sendToDatabase($customer);
It doesn't make sense with the current title and body, but maybe you want to send a "welcome" notification?
Are customers the model that logs in to your panel?Sorry,
The correct thing would be:
We can ignore the texts for now, I'm doing tests first.
When I make the deletion through the table action, the notification works.
However, when registration is done through the end-point, it is not displayed.
1. Did you check
created()
is called?
2. Is there an authenticated user?2. Is there an authenticated user? Yes.
image of my class:
What's the result you get when you add
dd(auth()->user());
inside the created()
method?
3. Do you see a record in the notifications
table?The deletion notification works when I delete it through the action.
Can we please keep the conversation in english? 😅
I put a dd() inside create and it didn't fire.
Well then something is wrong with your observer 😅
are you using queue?
php artisan queue:work
?No, I didn't implement a queue
what is the value from QUEUE_CONNECTION in .env file?
sync
laravel version?
Laravel Framework 10.48.14
try to add in your Customer model
I put it on but it didn't work
are you sure that is it creating the record?
The strange thing is that the deletion works. However, it is done through the filament panel
Yes, I'm checking the table
customers and notifications tables?
Only in the customer table.
weird.. could you try to send the notification using
afterCreate
hook?
https://filamentphp.com/docs/3.x/panels/resources/creating-records#lifecycle-hooks
just to see if it works..did you try something like
Log::info($message);
in the created
method and check the laravel.log?
While debugging I found this guy.
Apparently auth()->user() is arriving as null
are you using a different guard?
did you try using afterCreate? What is the output from
dd(auth()->id())
?After Create works even when registration is done externally to the filament?
no
are you trying to use this observer in the registration form?
My insertion is done through an external request. Create a controller to receive this information and then register. I want to use notification just to say that it has been registered.
No
are you sure that the user is logged?
if it is external, how
auth()->user()
will work?I believe this is exactly the problem. Even though the user is logged into the panel, the post is external, that is, it will not auth()->user()
No, this won’t work.
auth()->user()
retrieves the authenticated user instance, but it will only work inside your application, not outside of it.Any suggestion?
If you are using a service to handle this, you should also specify who will receive the notification