Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

laravel

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

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'd written (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.

$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?

like image 492
Stephen Mariano Cabrera Avatar asked Jan 25 '26 00:01

Stephen Mariano Cabrera


1 Answers

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?

I couldn't say for sure, but my guess is you're not using the other fields in a whereIn query.

$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

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,

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
)
like image 147
Alan Storm Avatar answered Jan 26 '26 17:01

Alan Storm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!