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
2,533 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,420 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 ...READ MORE

answered May 9, 2020 in Others by Anadya
1,333 views
0 votes
0 answers

How to compare two excel sheets

How to compare two excel sheets , ...READ MORE

Jul 18, 2021 in Others by Sri
• 3,190 points
659 views
0 votes
0 answers
0 votes
1 answer

Remove the Rupee symbol in Laravel

Although there are other approaches you may ...READ MORE

answered Jan 6, 2023 in Others by narikkadan
• 63,420 points
977 views
0 votes
2 answers

Laravel 5.4 to get data form API response

Input::get('var_name') READ MORE

answered Feb 14, 2019 in Blockchain by anonymous
1,443 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
892 views
0 votes
1 answer

Laravel 8 routes to controllers. SEO friendly URL structure

use regex to match the slugs  again use ...READ MORE

answered Feb 17, 2022 in Others by narikkadan
• 63,420 points
1,229 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP