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...}
In web.php:
Route::get('/read/notifications', 'Admin\\NotificationController@readNotification');
In Controller:
public function readNotification() {
$user = Auth::user();
$user->unreadNotifications()->update(['read_at' => now()]);
}
Please check the following code.
use Illuminate\Notifications\DatabaseNotification;
$notification = DatabaseNotification::find( $request->notification_id );
$notification->update(['read_at' => now()]);
$notification->save();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.