请问 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
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

试试这样写呢

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

试试这样写呢

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

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

4年前 评论

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