php - A more efficient way of saving 125 columns in a Laravel controller -
i have rather large table has 125 data inputs, each of has saved in separate column.
i have named each html input 1,2,3 etc... , same within table, things.
at moment, have following code:
$observation = new observation(); $observation->site_id = input::get('site_id'); $observation->result = input::get('1'); $observation->result_id = '1'; $observation->save(); is there way use loop iterate through 125 data inputs (input::get('x') , result_id = 'x') , save them all?
for($i=1; $i<=125; $i++) { $data[$i] = [ 'site_id'=>input::get('site_id'), 'result'=>input::get($i), 'result_id'=>$i ]; } using query builder:
db::table('table')->insert($data); // change table name. and if want use eloquent:
model::insert($data);
Comments
Post a Comment