save multiple data in laravel

Solutions on MaxInterview for save multiple data in laravel by the best coders in the world

showing results for - "save multiple data in laravel"
Matthew
17 May 2016
1    $head = Goodsreceiveheader::findorNew($request->id);
2    $head->referencenumber=$request->referencenumber;
3    $head->vendorid=$request->vendorid;
4    $head->date=$request->date;
5    $head->createdby=$request->createdby;
6    if ($head->save()){
7        $id = $head->id;
8        foreach($request->itemid as $key =>$item_id){
9            $data = array(
10                            'goodsreceiveheader_id'=>$id,
11                            'itemid'=>$request->itemid [$key],
12                            'quantity'=>$request->quantity [$key],
13                            'costprice'=>$request->costprice [$key],
14                );
15            Goodsreceivedetail::insert($data);
16        }
17    }
18
19    Session::flash('message','You have successfully create goods receive.');
20
21    return redirect('goodsreceive/goodsreceiveheader_list');
22
Leo
19 Oct 2018
1$data = $request->all();
2$finalArray = array();
3foreach($data as $key=>$value){
4   array_push($finalArray, array(
5                'fltno'=>$value['sflt'],
6                'model'=>$value['smodel'],
7                'engine'=>$value['sengine'],
8                'loc'=>$value['sloc'],
9                'serviceType'=>$value['sstye'],
10                'nextSvr'=> $value['snsvr'] )
11   );
12});
13
14Model::insert($finalArray);
15