mafortis mafortis - 1 month ago 8
PHP Question

Send notification from laravel store function

I have notification system which will send my posts to telegram channel as soon as they created.


This is source:
https://github.com/laravel-notification-channels/telegram


My notification system works just fine and the only issue i have is that i cannot get the correct post link, I send notification once post has created from my
PostController
under store function.

I have simply this code after
$post->save();


$post = \App\Post::first();
$post->notify(new \App\Notifications\PostPublished($post));


As you can see it always send post id
1
to my telegram channel i even tried
find(1)
and got same result.

My question is now: How to get the same post that created to be send to my channel?

Answer Source

code: $post = \App\Post::first(); get you first row in posts table

it means you always get first row in table

you dont need to use after $post->save();

just send notification without using $post = \App\Post::first(); after save

for example:

$post->save();
$post->notify(new \App\Notifications\PostPublished($post));