How to notify the person based on his post in laravel

Multi tool use
Multi tool use


How to notify the person based on his post in laravel



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?


Notification


notifiable_id


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
AppNotificationsPostNotif 12 AppUser



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?




1 Answer
1



I am using this table structure to send notification,



type Notification_id sender_id receiver_id


type


Notification_id


sender_id


receiver_id



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


userX


userY



I hope it works.





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 5:33


sender_id


receiver_id





I tried this already but it returns null when executing the Auth::user()->notify(new PostNotif());
– smzapp
Sep 14 '17 at 5:42



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





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 5:45





yeah. thank you. I found this one. stackoverflow.com/questions/43646085/…
– smzapp
Sep 14 '17 at 5:46






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

e8TIbMDKea,U
5NctAbG9 Rrl,Mr4itM,Elu953w81o8B,ab3JmbJNILKcWFkiUDoOMCley1d1 n7Y5,ml3ouT2g0iY Q1p GVzQscZw3

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications