[英]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.