简体   繁体   English

如何将特定用户的通知标记为已读并在laravel 5中发布?

[英]How to mark notification as read for particular user and post in laravel 5?

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. 因此,如何在显示数据列时访问数据列的post_id来删除该特定通知。

This is how it is stored in data column 这就是它存储在数据列中的方式

{"post_id":8,"title":"Example Post...}

In web.php: 在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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM