user3356666 user3356666 - 1 year ago 64
PHP Question

Laravel inserting multiple records in table

I try to do that

$names = $request->input('name');
$forid= $request->input('forid');
$ArrayNames = explode(",",$names);

$dataArrayNames = array();
foreach($ArrayNames as $name)
$dataArrayNames[] = array('name'=>$name, 'forId' => $forid);


But i get the error message
" preg_replace(): Parameter mismatch, pattern is a string while replacement is an array "

NOTE : $request->input('name') = 'nameA,nameB,nameC'

Answer Source

You are making an array of an array. Try this.