我正在努力使下面的查询正常工作。我最近遇到的错误是Object of class Closure could not be converted to string。
在Laravel (5.2)的旧版本中,我读到:$query是JoinClause的实例,它没有whereRaw()方法。(https://stackoverflow.com/a/47672758/4113027)
如何编写此查询以使其工作?
$results = DB::table('statement_transactions AS st')
->join('quickbooks_transactions AS qt', function ($join) {
$join->on('st.transaction_date', '=', 'qt.transaction_date');
$join->on('st.transaction_type_id', '=', 'qt.transaction_type_id');
$join->on('st.original_amount', '=', 'qt.original_amount');
$join->on('st.balance', '=', 'qt.balance');
})
->where('st.statement_id', $this->statement->id)
->where('st.has_match', 0)
->where('st.has_partial_match', 0)
->whereNull('st.quickbooks_transaction_id')
->orWhereRaw(function ($query) {
$query->whereRaw("LEFT(REPLACE(st.invoice_nbr, '-', ''), 5) = LEFT(REPLACE(qt.invoice_nbr, '-', ''), 5)")
->whereRaw("RIGHT(REPLACE(st.invoice_nbr, '-', ''), 5) = RIGHT(REPLACE(qt.invoice_nbr, '-', ''), 5)");
})
->select('st.id AS statement_transaction_id', 'qt.id AS quickbooks_transaction_id')
->get();发布于 2022-08-10 01:43:30
问题是:
->orWhereRaw(function ($query) {
$query->whereRaw("LEFT(REPLACE(st.invoice_nbr, '-', ''), 5) = LEFT(REPLACE(qt.invoice_nbr, '-', ''), 5)")
->whereRaw("RIGHT(REPLACE(st.invoice_nbr, '-', ''), 5) = RIGHT(REPLACE(qt.invoice_nbr, '-', ''), 5)");
})orWhereRaw()需要一个参数,一个字符串。相反,您将传递一个闭包(即您的function ($query) { ... })。
您需要将orWhereRaw更改为orWhere,后者确实接受闭包。
https://stackoverflow.com/questions/73298600
复制相似问题