Laravel-excel: Is there a way to use this library with Lumen

Created on 27 Nov 2020  ·  4Comments  ·  Source: Maatwebsite/Laravel-Excel

I wanna know if there is a way or tutorial to use this library with lumen.

question

Most helpful comment

安装环境不计算在内,请依照官方要求构建。
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.phpFacadeseloquent 的注释

$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 是因为我在这里碰到坑了,工作的时候很久都没好,下班回家一下子就好了,其他的使用方法与官方使用的一致。

All 4 comments

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.phpFacadeseloquent 的注释

$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 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wwendorf picture wwendorf  ·  3Comments

lucatamtam picture lucatamtam  ·  3Comments

pamekar picture pamekar  ·  3Comments

amine8ghandi8amine picture amine8ghandi8amine  ·  3Comments

vandolphreyes picture vandolphreyes  ·  3Comments