Laravel:如何按数据删除数据库通知行->postid
问题描述
当一个用户喜欢其他用户的帖子时,我已按照此链接在我的 laravel 博客应用中创建数据库通知
I have followed this link to create database notification in my laravel blog app , when one user likes other user's post
https://laravel.com/docs/5.5/notifications#database-notifications
我的应用程序成功创建数据库通知如下
my application successfully able to create database notification as follow
表格:通知
标识 |类型 |notifiable_id |通知类型 |数据 |read_at |created_at |更新时间
id | type | notifiable_id | notifiable_type | data | read_at | created_at | updated_at
现在我想通过数据删除数据库通知行->postid
now i want to delete database notification row by data->postid
我尝试过以下查询:
出错了:
QueryException SQLSTATE[42000]:语法错误或访问冲突:1064您的 SQL 语法有错误;检查手册对应于您的 MariaDB 服务器版本,以便使用正确的语法'>'$."postid"' = 17) 在第 1 行限制 1' (SQL: select * from通知位置(类型 = AppNotificationsPostLiked和 data->'$."postid"' = 17) 限制 1)
QueryException SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."postid"' = 17) limit 1' at line 1 (SQL: select * from notifications where (type = AppNotificationsPostLiked and data->'$."postid"' = 17) limit 1)
我也尝试过以下查询:
$result=DB::table('notifications')->whereRaw("JSON_EXTRACT(data,'$.postid') = ?", [17]);
$result=DB::table('notifications')->whereRaw("JSON_EXTRACT(data, '$.postid') = ?", [17]);
请建议我正确查询以在通知表中按 json (data.key) 获取行和删除行
please suggest me correct query to get row and delete row by json (data.key) in notifications table
推荐答案
它对我有用.你可以使用这个查询:
It worked for me. You can use this query:
这篇关于Laravel:如何按数据删除数据库通知行->postid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!