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 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入