请问 eloquent ORM 如何实现下列 SQL 语句?

laravel 有 whereRaw() 支持带 SQL 函数的语句查询,但好像没找到有叫 updateRaw() 的方法。

UPDATE `transaction_records` SET `relation_id` = CONCAT_WS('-', `seller_id`, `buyer_id`, `product_id`) WHERE `relation_id` = '0-0-0' ORDER BY `id` LIMIT 100

transaction_records 表有 id, seller_id, buyer_id, product_id, transaction_count, relation_id, created_at, updated_at 等字段,其中 id 为自增主键, seller_id, buyer_id, product_id, relation_id 有普通索引,且前三者默认值为 0 ,最后一个默认值为 ‘0-0-0’ 。

Long2Ge
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

试试这样写呢

TransactionRecord::where('relation_id', '0-0-0')->update(['relation_id' => DB::raw('CONCAT_WS('-', `seller_id`, `buyer_id`, `product_id`)')]);
5年前 评论
讨论数量: 2

试试这样写呢

TransactionRecord::where('relation_id', '0-0-0')->update(['relation_id' => DB::raw('CONCAT_WS('-', `seller_id`, `buyer_id`, `product_id`)')]);
5年前 评论
yybawang

->update(DB::raw('写在这里'))

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!