无法在 laravel 应用程序中保存资源 传递给 IlluminateDatabaseGrammar::p a


Failure to save resource in laravel app Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, null given

对于我的 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

我在堆栈跟踪中查找了我编写的一些代码(而不是来自 laravel 框架),唯一的代码是资源的控制器,它将我指向下一行。

$servicesFacilities =
DB::table('services_facilities')->whereIn('services_facilities_id',
Input::get('services_facilities'))->lists('name');

我知道这与我传递 NULL 并导致整个堆栈跟踪出现问题有关,但是当允许留空的其他字段没有发生这种情况时,为什么会在这里发生这种情况?

我知道这与我传递 NULL 并导致整个堆栈跟踪出现问题有关,但是当允许留空的其他字段没有发生这种情况时,为什么会在这里发生这种情况?

我不能肯定地说,但我的猜测是你没有在whereIn查询中使用其他字段。

$servicesFacilities =
DB::table('services_facilities')->whereIn('services_facilities_id',
    Input::get('services_facilities')
)->lists('name');

whereIn方法期望第二个参数是数组。 即,像这样的东西

DB::table('services_facilities')->whereIn('services_facilities_id',
    [1,2,3]
)

您的错误消息抱怨某些内容不是数组

传递给 Illuminate''Database''Grammar::p arameterize() 的参数 1 必须是数组类型,给定 null

快速修复将是这样的

//$ids = Input::get('services_facilities') ? Input::get('services_facilities') : [];    
$ids = Input::get('services_facilities', []) 
...
DB::table('services_facilities')->whereIn('services_facilities_id',
    $ids
)
相关文章:
  • 没有找到相关文章