Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json laravel按数据字段为用户选择通知_Json_Laravel_Notifications - Fatal编程技术网

Json laravel按数据字段为用户选择通知

Json laravel按数据字段为用户选择通知,json,laravel,notifications,Json,Laravel,Notifications,我有默认的laravel通知数据字段和默认的通知表 仅尝试根据用户的通知数据值为用户选择一些通知。我已在用户模型中创建了此函数 public function notifications_data($col) { $notifications = $this->notifications()->where('data' , function ($q) use ($col){ $q->where('appointment_id','0'); // quer

我有默认的laravel通知数据字段和默认的通知表 仅尝试根据用户的通知数据值为用户选择一些通知。我已在用户模型中创建了此函数

public function notifications_data($col)
{
$notifications = $this->notifications()->where('data' , function ($q) use ($col){
            $q->where('appointment_id','0'); // query data as table
        })->get();

return ($notifications);
}

我已将值保存在通知表列数据{“类型”:“约会”、“约会id”:“0”、“日期”:null、“更新者”:“状态”:“0”}

我如何获取此信息以获取状态为0或约会id为0的所有通知?也许这样可以:

public function notifications_data($col)
{
  $notifications = $this->notifications()
    ->where('data','LIKE','%"appointment_id":"0"%')
    ->orWhere('data','LIKE','%"status":"0"%')
    ->get();

return ($notifications);
}

使用Laravel的查询生成器:

public function notifications_data()
{
    $notifications = DB::table('notifications')  //Specify the table you want to query
        ->where('status',0)    //Where status = 0
        ->orWhere('appointment_id',0)   //or appointment_id = 0
        ->get();

    return $notifications;
}
您还可以使用:

public function notifications_data($col)
{
  $notifications = $this->notifications()
    ->where('data->appointment_id', 0)
    ->orWhere('data->status', 0)
    ->get();

  return ($notifications);
}

我不确定这是否是正确的方法,但它是有效的!哇,这是什么魔法?它是特定于Laravel还是php?