Laravel Call to undefined method Maatwebsite Excel Excel load

0 votes

Whenever I try to run my import script, I have problems like this. I tried switching from Excel load() to Excel import(), but it doesn't work. What ought I do to solve this issue? Whenever I try to run my import script, I have problems like this. I tried switching from Excel load() to Excel import(), but it doesn't work. What ought I do to solve this issue?

 public function postImport(Request $request)
{
    // $this->validate($request, [
    //     'file'  => 'required|mimes:xls,xlsx'
    //    ]);
  
       $path = $request->file('file')->getRealPath();
  
       $data = Excel::load($path)->get();
    // $data = Excel::toArray([],$path);
       
  
       if($data->count() > 0)
       {
        foreach($data->toArray() as $key => $value)
        {
         foreach($value as $row)
         {
          $insert_data[] = array(
            'nomorUrut' => $row[0],
            'namaSupplier' => $row[1], 
            'singkatanSupplier' => $row[2], 
            'tipeSupplier' => $row[3], 
            'alamatSupplier' => $row[4], 
            'kodePosSupplier' => $row[5], 
            'noTelpSupplier' => $row[6], 
            'noFax' => $row[7],
            'emailSupplier' => $row[8],
            'contakSupplier' => $row[9],
            'hp' => $row[10],
          );
         }
        }
  
        if(!empty($insert_data))
        {
         DB::table('uplSupplier')->insert($insert_data);
        }
       }
       return back()->with('success', 'Excel Data Imported successfully.');
    //   }
Apr 9, 2023 in Others by Kithuzzz
• 38,010 points
3,113 views

1 answer to this question.

0 votes

In the app's exports, I've added InterfaceSupplier (as UplSupplierImport). I'm having a problem with "Array to string conversion" once more. This is the new InterfaceSupplier that I've added to my app/export under the name UplSupplierImport. Because the new code for the controller was the same as your previous code:

class InterfaceSupplier implements ToArray
{
    public function array(array $row)
    {
        return [
            'nomorUrut' => $row[0],
            'namaSupplier' => $row[1],
            'singkatanSupplier' => $row[2],
            'tipeSupplier' => $row[3],
            'alamatSupplier' => $row[4],
            'kodePosSupplier' => $row[5],
            'noTelpSupplier' => $row[6],
            'noFax' => $row[7],
            'emailSupplier' => $row[8],
            'contakSupplier' => $row[9],
            'hp' => $row[10],
        ];
    }


}

and this the controller code:

public function postImport(Request $request)
{

    $path = $request->file('file')->getRealPath();
    $insert_data = Excel::toArray(new InterfaceSupplier(), $path);

    if(!empty($insert_data))
    {
        DB::table('uplSupplier')->insert($insert_data);
    }

    return back()->with('success', 'Excel Data Imported successfully.');
}
answered Apr 9, 2023 by narikkadan
• 63,720 points

Related Questions In Others

0 votes
1 answer

Is it possible to vibrate from broadcast receiver during incoming call?

Hello Android Native Development I have found some ...