【问题标题】:filter notifications from 'notifications' table 'data' field - Laravel从“通知”表“数据”字段中过滤通知 - Laravel
【发布时间】:2017-08-29 08:55:22
【问题描述】:

这是默认的 laravel notifications data 字段

{
  "type":"Update Appointment",
  "appointment_id":"379",
  "date":null,
  "updated_by":"Mahir",
  "status":"2"
}

controller 我想用status = 2 获取所有通知并标记为已读

Laravel 5.3 文档展示

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

foreach ($user->unreadNotifications as $notification) {
    $notification->markAsRead();
}

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

更新:寻找类似的东西

$noti = $user->unreadNotifications->where('data->status',"2");

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

【问题讨论】:

  • 说真的,知道一个回答:(

标签: laravel notifications laravel-5.3


【解决方案1】:

根据 laravel 5.6:JSON Where Clauses

并使用 MySQL 5.7

希望这个回答对你有帮助

【讨论】:

    【解决方案2】:
    $user = $user->unreadNotifications->where('data.complaint_id',1);
    

    它对我来说很好,我希望它对你有帮助。

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-01-30
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-18
        相关资源
        最近更新 更多