Tuesday 15 January 2013

Laravel 4 updating all records with array gives me parameter mismatch error -



Laravel 4 updating all records with array gives me parameter mismatch error -

trying update each row of table multidimensional array created querying database.

the array:

array ( [0] => array ( [community_id] => ap [floorplan_code] => ap1-1a [name] => 33flat [hidden] => 0 ) [1] => array ( [community_id] => ap...

here code i'm using in effort update:

$floorplan = new floorplan; //create new instance $floorplan->get(); //get rows $floorplan->update($floorplanmappedarray); //map db columns array , update

error message: preg_replace(): parameter mismatch, pattern string while replacement array.

the parameter mismatch came fact trying shove multidimensional array single row. therefore, needed foreach loop index through multidimensional array.

i thought there magical way utilize update() method in same way insert() method used. apparently, there not.

here code solved parameter mismatch error:

foreach ($floorplanmappedarray $floorplan) { floorplan::where('floorplan_code', $floorplan['floorplan_code'])->update($floorplan); }

arrays laravel-4 eloquent

No comments:

Post a Comment