-1

I was able to create a Notification table using migration. Also I can save notification if a user(X) replies to the post of user(Y). Now, the problem is, I want to send the notification to user(Y), but then, the notifiable_id saves the id of user(X). How can user(Y) receive the notification then?

 Auth::user()->notify(new PostNotif());

Example:

user(X) ID is : 12 and,
user(Y) ID is : 24

The notifications table looks like this:

type                          notifiable_id  notifiable_type 
App\Notifications\PostNotif       12              App\User

I expected that the notifiable_id should be the ID of user(Y) which is 24 and not 12.

Since, the user(Y) submitted a post and user(X) responded to that post, how can user(Y) be notified in this case?

EDIT

Also, I expect two IDs to be inserted into the database notification. One for the user who created the post and the other for the one who responded to the post.

Does anybody know about this?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
smzapp
  • 809
  • 1
  • 12
  • 33

1 Answers1

0

I am using this table structure to send notification,

type Notification_id sender_id receiver_id

you can store userX in sender_id and userY in receiver_id, wise a versa.

I hope it works.

iLaxo Mit
  • 77
  • 6
  • Yeah, I got your point. But, how to save `sender_id` and `receiver_id` into the database since, notify method does not include saving of data other than the default fields. – smzapp Sep 14 '17 at 05:33
  • I tried this already but it returns null when executing the `Auth::user()->notify(new PostNotif());` – smzapp Sep 14 '17 at 05:42
  • Add new field sender_id and receiver_id in notification table, so when you call send notification ex: X is sender then store X id in sender_id and Y (multiple user) is receiver then you have to store multiple notification in this table – iLaxo Mit Sep 14 '17 at 05:45
  • yeah. thank you. I found this one. https://stackoverflow.com/questions/43646085/laravel-5-4-5-3-customize-or-extend-notifications-database-model – smzapp Sep 14 '17 at 05:46