我想将查看特定帖子的用户的通知标记为
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...}
答案 0 :(得分:0)
在web.php中:
Route::get('/read/notifications', 'Admin\NotificationController@readNotification');
在控制器中:
public function readNotification() {
$user = Auth::user();
$user->unreadNotifications()->update(['read_at' => now()]);
}
答案 1 :(得分:0)
请检查以下代码。
use Illuminate\Notifications\DatabaseNotification;
$notification = DatabaseNotification::find( $request->notification_id );
$notification->update(['read_at' => now()]);
$notification->save();