安装方式
composer require maatwebsite/excel
//若不成功
composer require maatwebsite/excel --ignore-platform-reqs
创建类
php artisan make:import excelImport
创建后生成excelImport文件, 不需要修改什么
<?php
namespace App\Imports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\Importable;
class excelImport implements ToCollection
{
use Importable;
/**
* @param Collection $collection
*/
public function collection(Collection $collection)
{
}
}
使用方法
public function excelImport($file)
{
$data = Excel::toArray(new excelImport(), $file);
dd($data);
}