Call to undefined method Maatwebsite\Excel\Excel::

2019-02-24 08:51发布

I'm trying to import excel file (.xlsx) using maatwebsite 3.0. How to fix This error

Call to undefined method Maatwebsite\Excel\Excel::load()

My controller

public function importsave(Request $request)
{
   if($request->hasFile('excel'))
    {
        $path = $request->file('excel')->getRealPath();
        $data= Excel::load($path, function($reader) {})->get();
        if(!empty($data) && $data->count())
        {
            foreach($data->toArray() as $key=>$value)
            {
                if(!empty($value))
                {
                    Employee::insert($value);
                }
            }
        }
    }
}

3条回答
啃猪蹄的小仙女
2楼-- · 2019-02-24 09:01

Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551

I suggest you switch to version 2.*.

查看更多
该账号已被封号
3楼-- · 2019-02-24 09:05

Hi there in version 3 the load method was remove so switch back to version two like so composer require "maatwebsite/excel:~2.1.0"

查看更多
闹够了就滚
4楼-- · 2019-02-24 09:07

Version 3.0 of Laravel Excel doesn't handle imports.

You could also use an alternative package that works with import such as:

Both handles import.

You could also switch to version 2, but it means use an old version of a lib.

查看更多
登录 后发表回答