1、安装插件
Maatwebsite\Excel,目前的最高版本应该是3.1.19
composer require maatwebsite/excel
2、在config/app.php 中注册 服务提供类 providers数组中
Maatwebsite\Excel\ExcelServiceProvider::class,
3、生成配置文件
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
4、百度了一些资料说是采用
Excel::load($fileName, function ($reader){
foreach ($reader->get() as $item){
dump($item);
}
});
但是在实际操作中发现会报错,说load方法没有定义,查阅资料后得知这个方法是在2.*版本里才有的,要么降级到2.*,这个肯定是不愿意的,毕竟新的东西更好嘛(也有那例外的)。
所以
Excel::toArray($request, $file);
这样就OK了。