【问题标题】:Class excel does not exist in Laravel 5.2Laravel 5.2 中不存在类 excel
【发布时间】:2017-04-26 13:32:50
【问题描述】:

我正在尝试在 laravel 5.2 中下载 excel。但是服务器给出了这个错误

Container.php 第 734 行中的ReflectionException:Excel 类没有 存在

这在 localhost 中可以正常工作

这是我的功能

 return Excel::create('users', function($excel) use($datas) {
            return   $excel->sheet('Sheet 1', function($sheet) use($datas) {

                $datasheet = array();
                $datasheet[0]  =   array('id','Voucher No','Code','Expiry Date','Created_at');
                $i=1;
                foreach($datas as $datanew){
                    $datasheet[$i] = array( @$datanew['id'],
                        $datanew['vouchers_no'],
                        $datanew['code'],
                        $datanew['date'],
                        $datanew['created_at'],
                    );
                    $i++;
                }
                $sheet->fromArray($datasheet);

            });

        })->download('xlsx');

用过的包

maatwebsite/excel

我在 config/app.php

中添加了这两行
Maatwebsite\Excel\ExcelServiceProvider::class,
'Excel' => Maatwebsite\Excel\Facades\Excel::class,

在本地运行正常,但显示错误

【问题讨论】:

    标签: php excel laravel-5 laravel-5.2


    【解决方案1】:

    我在生产服务器中遇到了类似的行为。 通过执行解决:

    composer update
    composer update --no-scripts
    

    第一个更新所有对象; 另一个是为了避免在更新期间可能会失败的脚本执行

    【讨论】:

    【解决方案2】:

    对我来说,当我在 laravel 中创建 vendor 文件夹的 zip 文件并将其替换为服务器,因为我在那里包含了新的软件包。客户端没有为 ssh 终端 启用最终解决方案,我删除了 bootstrap/cache 中的文件,它运行良好。

    【讨论】:

      猜你喜欢
      • 2016-06-30
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2017-01-20
      相关资源
      最近更新 更多