[英]How to mark notification as read for particular user and post in laravel 5?
我想将查看特定帖子的用户的通知标记为已读
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'));
}
它给出了这个错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'data['post_id']' in 'where clause'
因此,如何在显示数据列时访问数据列的post_id来删除该特定通知。
这就是它存储在数据列中的方式
{"post_id":8,"title":"Example Post...}
在web.php中:
Route::get('/read/notifications', 'Admin\\NotificationController@readNotification');
在控制器中:
public function readNotification() {
$user = Auth::user();
$user->unreadNotifications()->update(['read_at' => now()]);
}
请检查以下代码。
use Illuminate\Notifications\DatabaseNotification;
$notification = DatabaseNotification::find( $request->notification_id );
$notification->update(['read_at' => now()]);
$notification->save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.