I wanna know if there is a way or tutorial to use this library with lumen.
We don't officially support it, but I know people have used it with Lumen. Try Stackoverlow or Laracasts when you need help.
安装环境不计算在内,请依照官方要求构建。
1、安装 lumen
composer create-project --prefer-dist laravel/lumen blog
2、安装 Maatwebsite/Laravel-Excel,注意版本支持
cd blog
composer require maatwebsite/excel
3、在 bootstrap/app.php 中注册服务
$app->register(Maatwebsite\Excel\ExcelServiceProvider::class);
4、去除 bootstrap/app.php 中 Facades 和 eloquent 的注释
$app->withFacades();
$app->withEloquent();
5、使用示例
在 app\Exports 目录下创建文件 TestExport,内容如下
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromArray;
class TextExport implements FromArray
{
public function array(): array
{
return [
[1, 2, 3],
[2, 3, 4],
];
}
}
创建控制器 TestController,创建 index 方法并添加内容 Excel::store
<?php
namespace App\Http\Controllers;
use App\Exports\TextExport;
use Maatwebsite\Excel\Facades\Excel;
class TestController extends Controller
{
public function index()
{
Excel::store(new TextExport(), 'hi.xls');
}
}
在 routes/web.php 中添加路由
$router->get('/test', 'TestController@index');
进行访问 http://xxx/test,页面提示 Class 'League\Flysystem\Adapter\Local' not found
安装 League/Flysystem
composer require League/Flysystem
ok,再访问就好啦,可以在 storage/app 目录下看到已经生成了 hi.xls 文件
注意:只写了 Excel::store 是因为我在这里碰到坑了,工作的时候很久都没好,下班回家一下子就好了,其他的使用方法与官方使用的一致。
@twelife
thanks my friend ... I did just like you said but there was a problem
I was still getting Class 'League\Flysystem\Adapter\Local' not found error
The problem solved by downgrade League/Flysystem from version "^2.*" to "^1.*"
@twelife --
$app->register(\Maatwebsite\Excel\ExcelServiceProvider::class);
This worked for me when registering Laravel Excel in a new Laravel package to write a custom import script. Thank you 👍
Most helpful comment
安装环境不计算在内,请依照官方要求构建。
1、安装
lumen2、安装
Maatwebsite/Laravel-Excel,注意版本支持3、在
bootstrap/app.php中注册服务4、去除
bootstrap/app.php中Facades和eloquent的注释5、使用示例
在
app\Exports目录下创建文件TestExport,内容如下创建控制器
TestController,创建index方法并添加内容Excel::store在
routes/web.php中添加路由进行访问
http://xxx/test,页面提示Class 'League\Flysystem\Adapter\Local' not found安装
League/Flysystemok,再访问就好啦,可以在
storage/app目录下看到已经生成了hi.xls文件注意:只写了
Excel::store是因为我在这里碰到坑了,工作的时候很久都没好,下班回家一下子就好了,其他的使用方法与官方使用的一致。