dqpfl2508589 2017-02-07 05:14
浏览 81
已采纳

调用未定义的方法Illuminate \ Database \ Query \ Builder :: lists()和[避免csv中的重复数据] [重复]

error:=> Call to undefined method Illuminate\Database\Query\Builder::lists()

And how to avoid duplicate data in .CSV file type..

public function import(Request $request){

     $this -> validate($request, [
       'import_file' => 'required|mimes:csv,xlsx|max:2048',
    ]);

     if($request->hasFile('import_file')){

        $rollno = Student::lists('rollno')->toArray();

        $file = $request->file('import_file') ;

        $fileName =  date('Y-m-d_H-i-s')."-".$file->getClientOriginalName();

        $destinationPath = public_path().'/uploads/' ;

        $file->move($destinationPath,$fileName); 

        $path=$destinationPath.$fileName;//"uploads/testfile_xlsx.xlsx";

        $data = Excel::load($path, function($reader) {})->get();

        if(!empty($data) && $data->count()){

            foreach ($data as $key => $value) {

                if (in_array($value->rollno, $rollno))

                continue;

                $insert[] = ['name' => $value->name,'rollno' => $value->rollno,'department' => $value->department, 'course' => $value->course,'image_name'=>''];

            }
            if(!empty($insert)){
                DB::table('students')->insert($insert);
                return back()->with('success','Insert Record successfully.');

            }

        }

        else{unlink($path); return back()->with('error','Please Check your file. No Rows'); }

    }

    return back()->with('error','Something is wrong there.');
}
</div>
  • 写回答

1条回答 默认 最新

  • dsa45132 2017-02-07 05:42
    关注

    If your are using laravel version >=5.3 then use pluck method instead of lists. Answer is already given here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?