sumitgroup
2 months ago
177
0
Laravel

Error in Data Import from Excel in Laravel 6?

Posted 2 months ago by sumitgroup

I am getting error when i am Importing data from Excel Sheet, I am doing it by Controller. and I am getting this error Call to undefined method Maatwebsite\Excel\Excel::load()

Please let me know if it can be possible by Model,....

Here are my Model..

  <?php
      namespace App;
      use Illuminate\Database\Eloquent\Model;
      class Lead extends Model
     {
protected $primaryKey = 'lId';
    }

Here are my Controller Code...

 public function import(Request $request){
    $this->validate($request, [
        'select_file' => 'required|mimes:xls, xlsx'
    ]);
    $path=$request->file('select_file')->getRealPath();
    $data=Excel::load($path)->get();
    if($data->count() > 0)
    {
        foreach ($data->toArray() as $key => $value) 
        {
            foreach($valuse as $row)
            {
                $insert_data[]=array(
                    'Name'=>$row['name'],
                    'Project'=>$row['project'],
                    'Follow up Date'=>$row['followup'],
                    'Lead Source'=>$row['lead_source'],
                    'Email Id'=>$row['email'],
                    'Message'=>$row['message'],
                    'Phone Number'=>$row['number'],
                    'Status'=>$row['status'],
                );
            }
        }
        if(!empty($insert_data))
        {
            DB::table('leads')->insert($insert_data);
        } 
    }
    return back()->with('success', 'Excel Data Imported successfully.');
}

and here are my view code...

<form action="{{ route('import') }}" method="POST" enctype="multipart/form-data">
								@csrf
								<input type="file" name="select_file" class="form-control">
								<br>
								<input type="submit" name="upload" class="btn btn-primary" value="Upload">
							</form>

Here are my routes..

    Route::post('lead/import', '[email protected]')->name('import');

Please sign in or create an account to participate in this conversation.