Json laravel按数据字段为用户选择通知
我有默认的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
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?