I want to mark a notification as read for a user who views a particular post
public function show(Post $post)
{
$notification_for_user = auth()->user()->unreadNotifications()->where("data['post_id']", $post->id)->first()->update(['read_at' => now()]);
return view('post.show', compact('post'));
}
It gives this error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'data['post_id']' in 'where clause'
So how can i access data column's post_id to delete that particular notification for the user when it is displayed.
This is how it is stored in data column
{"post_id":8,"title":"Example Post...}
Please check the following code.
use Illuminate\Notifications\DatabaseNotification;
$notification = DatabaseNotification::find( $request->notification_id );
$notification->update(['read_at' => now()]);
$notification->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With