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

时间:2018-01-17 11:12:07

标签: php laravel laravel-5 notifications

我想将查看特定帖子的用户的通知标记为

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...}

2 个答案:

答案 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();