从“通知”表“数据”字段过滤通知 - Laravel

Ja2*_*a22 6 notifications laravel laravel-5.3

这是默认的 Laravelnotifications data字段

{
  "type":"Update Appointment",
  "appointment_id":"379",
  "date":null,
  "updated_by":"Mahir",
  "status":"2"
}
Run Code Online (Sandbox Code Playgroud)

controller我想获得所有通知status = 2并将其标记为已读

Laravel 5.3 文档显示

$user = App\User::find(1);

foreach ($user->unreadNotifications as $notification) {
    $notification->markAsRead();
}
Run Code Online (Sandbox Code Playgroud)

我如何修改它以获取所有通知 status = 2

更新:寻找这样的东西

$noti = $user->unreadNotifications->where('data->status',"2");
Run Code Online (Sandbox Code Playgroud)

注意:我的数据库不支持json数据类型。

Ham*_*ndi 5

根据 laravel 5.6: JSON Where Clauses

并使用 MySQL 5.7

我希望这个答案对你有帮助


小智 1

我认为,您可以创建自己的频道(另请参阅 Illuminate\Notifications\Channels\DatabaseChannel),您可以在其中重写 send() 方法来保存通知。在此之前,您可以编写迁移来更新“通知”表以添加自定义过滤字段。请参阅: https: //laravel.com/docs/5.5/notifications#custom-channels

对不起我的英语不好。希望,你会明白。