gpt4 book ai didi

php - SQLSTATE[23000] : Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5. 5

转载 作者:行者123 更新时间:2023-11-29 04:15:15 24 4
gpt4 key购买 nike

我只是不知道我的代码有什么问题以及为什么会产生这个错误

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous (SQL: select * from processes inner join bags on processes.bag_id = bags.id where bags.type = Recyclable and date(processes.created_at) = 2018-09-18 00:00:00 order by created_at desc limit 1) and here's my code

$bag = Bagcollect::join('bags', 'bagcollects.bag_id', '=', 'bags.id')
->select('bags.type')
->where('bagcollects.bag_id', $request->input('bag_id'))
->first();

//this query produce error
$processexist = Process::join('bags', 'processes.bag_id', '=', 'bags.id')
->where('bags.type', $bag->type)
->whereDate('processes.created_at', Carbon::today())
->latest()
->first();

最佳答案

您需要在 latest() 中指定完整的列。 latest('process.created_at') 或不使用 latest() 而使用自定义 orderBy。

关于php - SQLSTATE[23000] : Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5. 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52387552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com