Laravel : How to delete Database Notification row by data-gt;postid(Laravel:如何按数据删除数据库通知行-gt;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
id = 0b2a7fdf-eea4-4982-a86d-e874bb4f28ef
type = AppNotificationsPostLiked
notifiable_id= 48
data = { "event":"LIKE",
"postid":17,
"sender":{
"id":50,
"name":"Developer",
}
}
read_at = NULL
created_at = 2018-04-07 12:46:42
updated_at = 2018-04-07 12:46:42
现在我想通过数据删除数据库通知行->postid
now i want to delete database notification row by data->postid
我尝试过以下查询:
DB::table('notifications')
->where('type','AppNotificationsPostLiked')
->where('data->postid',17)
->first();
出错了:
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]);
{
connection: { },
grammar: { },
processor: { },
bindings: {
select: [ ],
join: [ ],
where: [
17
],
having: [ ],
order: [ ],
union: [ ]
},
aggregate: null,
columns: null,
distinct: false,
from: "notifications",
joins: null,
wheres: [
{
type: "raw",
sql: "JSON_EXTRACT(`data`, '$.postid') = ?",
boolean: "and"
}
],
groups: null,
havings: null,
orders: null,
limit: null,
offset: null,
unions: null,
unionLimit: null,
unionOffset: null,
unionOrders: null,
lock: null,
operators: [
"=",
"<",
">",
"<=",
">=",
"<>",
"!=",
"<=>",
"like",
"like binary",
"not like",
"between",
"ilike",
"&",
"|",
"^",
"<<",
">>",
"rlike",
"regexp",
"not regexp",
"~",
"~*",
"!~",
"!~*",
"similar to",
"not similar to",
"not ilike",
"~~*",
"!~~*"
],
useWritePdo: false
}
请建议我正确查询以在通知表中按 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:
->where('data', 'like', '%"postid":17%' )->first();
这篇关于Laravel:如何按数据删除数据库通知行->postid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel:如何按数据删除数据库通知行->postid
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01