mafortis mafortis - 6 months ago 46
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:

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
under store function.

I have simply this code after

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

As you can see it always send post id
to my telegram channel i even tried
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->notify(new \App\Notifications\PostPublished($post));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download