I have a form within a table that has different fields. I want to be able to store all the data once. I hve search Stack overflows, all the answer i got did not solve the issue.Hence, I have to post my own question. The View
<td><input type="text" name="sflt[]" value="{{ $r['fltno'] }}" readonly="readonly" class="form-control"/></td>
<td><input type="text" name="smodel[]" value="{{ $r['model']}}" readonly="readonly" class="form-control"/></td>
<td><input type="text" name="sengine[]" value="{{ $r['engine_type'] }}" readonly="readonly" class="form-control"/></td>
<td><input type="text" name="sloc[]" value="{{ $r['location'] }}" readonly="readonly" class="form-control"/></td>
<td><input type="text" name="sstye[]" value="{{ $sty }}" readonly="readonly" class="form-control"/></td>
<td><input type="text" name="snsvr[]" value="{{ $nsvr}}" readonly="readonly" class="form-control"/></td>
Controller
$data = [];
**//Get the input variables**
$fltno= $request['sflt'];
$model = $request['smodel'];
$engine = $request['sengine'];
$loc = $request['sloc'];
// Store each varaibles as you fetch into the empty array
foreach($fltno as $fltno)
{
$data[] = [
'fltno'=>$request['sflt'],
'model'=>$request['smodel'],
'engine'=>$request['sengine'],
loc'=>$request['sloc'],
'serviceType'=>$request['sstye'],
'nextSvr'=> $request['snsvr']
];
}
ModelName::insert($data);
When I execute this, it throws error of: Invalid argument supplied for foreach()
Please, what am i doing wrong or what is the best way to insert all these data at once into the Database