当买家用户向卖家发送问题时,我已经关注this链接在我的laravel电子商务应用中创建数据库通知
我的应用程序成功地能够如下创建数据库通知
表:通知
id | type | notifiable_id | notifiable_type | data | read_at | created_at | updated_at
id = 0b2a7fdf-eea4-4982-a86d-e874bb4f28ef
type = App\Notifications\BuyerQuestionNotification
notifiable_id= 48
data = {"message":"Someone asked question for Hostelfe","url":"#", "question_id":12024}
read_at = NULL
created_at = 2018-04-07 12:46:42
updated_at = 2018-04-07 12:46:42
现在我想通过data-> question_id删除数据库通知行
I have tried below query :
DB::table('notifications')
->where('type','App\Notifications\SellerAnswerNotification')
->where('data->question_id',2079107489)
->first();
得到错误:
[2019-03-31 13:22:03] local.ERROR:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在'>'$附近使用正确的语法。“question_id”'=?'在第1行(SQL:select * from
notifications
,其中type
= App \ Notifications \ SellerAnswerNotification和data
- >'$。“question_id”'= 2079107489)
我也试过下面的查询:
$result=DB::table('notifications')->whereRaw("JSON_EXTRACT(data, '$.question_id') = ?", [2079107489]);
但得到了类似的错误
如何更正查询以通过通知表中的json获取行和删除行?
当你执行json_decode($ data)然后尝试在哪里($ data ['question_id'])