未能在 Laravel 应用程序中保存资源参数 1 传递给 Illuminate\Database\Grammar::parameterize() 必须是数组类型,给定 null
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27869188/
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
Failure to save resource in laravel app Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, null given
提问by Stephen Mariano Cabrera
For one of the resources of my laravel application, I get an error when leaving a field blank:
对于我的 Laravel 应用程序的其中一项资源,将字段留空时出现错误:
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, null given, called in /var/www/html/pfladmin/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 309 and defined
I looked in the stack trace for some code that I'dwritten (as opposed to coming from the laravel framework) and the only one was the controller for the resource, which pointed me to the following line.
我在堆栈跟踪中查看了我编写的一些代码(而不是来自 laravel 框架),唯一的一个是资源的控制器,它将我指向以下行。
$servicesFacilities =
DB::table('services_facilities')->whereIn('services_facilities_id',
Input::get('services_facilities'))->lists('name');
I get that this has something to do with my passing a NULL around and this causing problems all over the stack trace, but why would that be happening here when it isn't happening for other fields that are allowed to be left blank?
我知道这与我传递 NULL 值有关,这会导致整个堆栈跟踪出现问题,但是当其他允许留空的字段没有发生这种情况时,为什么会在这里发生这种情况?
回答by Alan Storm
I get that this has something to do with my passing a NULL around and this causing problems all over the stack trace, but why would that be happening here when it isn't happening for other fields that are allowed to be left blank?
我知道这与我传递 NULL 值有关,这会导致整个堆栈跟踪出现问题,但是当其他允许留空的字段没有发生这种情况时,为什么会发生这种情况?
I couldn't say for sure, but my guess is you're not using the other fields in a whereIn
query.
我不能肯定,但我的猜测是您没有在whereIn
查询中使用其他字段。
$servicesFacilities =
DB::table('services_facilities')->whereIn('services_facilities_id',
Input::get('services_facilities')
)->lists('name');
The whereIn
method expects the second parameter to be an array. i.e., something like this
该whereIn
方法要求第二个参数是一个数组。即,像这样的东西
DB::table('services_facilities')->whereIn('services_facilities_id',
[1,2,3]
)
Your error message is complaining about something not being an array
您的错误消息抱怨某些不是数组
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, null given,
传递给 Illuminate\Database\Grammar::parameterize() 的参数 1必须是 array 类型,给定 null,
The quick fix would be something like
快速修复将类似于
//$ids = Input::get('services_facilities') ? Input::get('services_facilities') : [];
$ids = Input::get('services_facilities', [])
...
DB::table('services_facilities')->whereIn('services_facilities_id',
$ids
)