Inability to save resource in laravel application Argument 1 is passed to Illuminate \ Database \ Grammar :: parameterize () must be from array of types, null

For one of the resources of my laravel app, I get an error when leaving a field:

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 at the stack trace for some code I wrote (as opposed to going out of the laravel framework) and the only one was the controller for the resource which pointed me to the next line.

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

      

I realize this is because I am missing NULLs and this is causing problems throughout the entire stack trace, but why is this happening here when it doesn't happen for other fields that are allowed to be left blank ??

+3


source to share


1 answer


I understand this is because I am missing NULLs and this is causing problems throughout the entire stack trace, but why is this happening here when it does not happen for other fields that are allowed to be left blank?

I couldn't say for sure, but I guess you are not using other fields in the request whereIn

.

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

      

The method whereIn

expects the second parameter to be an array. that is, something like this

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

      



Your error message is complaining about not being an array

Argument 1 passed to Illuminate \ Database \ Grammar :: parameterize () must be an array of types , null is specified,

A 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
)

      

+3


source







All Articles