简体   繁体   中英

Get all the rows except for the fields Laravel: Excel

So I have an excel file with a format like this

在此处输入图像描述

在此处输入图像描述

I'm trying to get all the rows below the row1

This would be the records of John Doe and Mc Doe

Currently I have this code from controller

    $dateTime = date('Ymd_His');
    $file = $request->file('file');
    $fileName = $dateTime . '-' . $file->getClientOriginalName();
    $savePath = public_path('/upload/projectlist/');
    $file->move($savePath, $fileName);

    $excel = Importer::make('Excel');
    $excel->load($savePath.$fileName);
    $collection = $excel->getCollection();

    if(sizeof($collection[1]) == 5){

        for($row=1; $row<sizeof($collection); $row++){
            try{
                dd($collection[$row]);
            }
            catch(\Exception $e){
                return redirect()
                ->back()
                ->with(['errors'=>$e->getMessage()])
                ->with('modal',$modal);
            }
        }
    }else{
        return redirect()
        ->back()
        ->with(['errors'=> [0=> 'Please provide date in file according to your format.']])
        ->with('modal',$modal);
    }

And this gives me an output like this

在此处输入图像描述

Which the record of John Doe only. How can I get all the rows except for row1 ?

here you get all the value if remove dd & it save every row in a array & dd that array outside the for loop then you get all results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM