laravel 传递给 Illuminate\Database\Grammar::parameterize() 的参数 1 必须是数组类型,给定的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47952254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, object given
提问by Anna.Klee
I am using Laravel 5.5
and I have translated the following query:
我正在使用Laravel 5.5
并翻译了以下查询:
'SELECT *
FROM instruments
LEFT join financials on instruments.id=financials.instruments_id
WHERE financials.id IN
( SELECT MAX(financials.id)
FROM financials
GROUP BY financials.instruments_id )
ORDER BY instruments.id ASC'
into eloquent:
雄辩地:
$overviewArray = DB::table('instruments')
->leftJoin('financials', 'instruments.id', '=', 'financials.instruments_id')
->whereIn('financials.id', DB::raw('SELECT MAX(financials.id)
FROM financials
GROUP BY financials.instruments_id )
ORDER BY instruments.id ASC'))->get()->toArray();
However, I get the following error:
但是,我收到以下错误:
In Grammar.php line 135:
在 Grammar.php 第 135 行:
Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, object given, called
in C:\Users\admin\Desktop\Coding Projects\laravel_project\vendor\laravel\framework\src\Illuminate\Database\Query\Gramm
ars\Grammar.php on line 250
My guess is that my eloquent query is wrong? Any suggestions what is wrong with it?
我的猜测是我雄辩的查询是错误的?有什么建议吗?
I appreciate your replies!
我感谢您的回复!
采纳答案by yrv16
$overviewArray = DB::table('instruments')
->leftJoin('financials', 'instruments.id', '=', inancials.instruments_id')
->whereIn('financials.id', function($query){
$query->select(DB::raw('MAX(financials.id)'))->
from('financials')->
groupBy('financials.instruments_id');})
->orderBy('instruments.id')
->get()
->toArray();
I guess it will be ok.
我想会没事的。