【问题标题】:How to make File Upload with Laravel excel using chunk method?如何使用块方法使用 Laravel excel 进行文件上传?
【发布时间】:2018-06-05 09:42:01
【问题描述】:
public function uploadNotaCorte(Request $request, EstadoRepository $estadoRepository)
{
    $error      = array();
    $path       = $request->file('file')->getRealPath();
    $notasCorte = Excel::load($path, function($reader) {
    })->get();

    $chunk      = $notasCorte->chunk(100);

    foreach ($notasCorte as $key => $notaCorte) {
    //RULES
   }return  $error;
}

** 大家好,我是编程新手,我很难实现块方法,所以上面的 dodigo 通常适用于小文件加上较大的错误文件,因为它的大小。 我需要上传一个包含 120,000 条记录的文件,并且我正在尝试为此使用块,我不知道我会做错什么已经查看了更多非常简单的文档并且我无法解决问题任何人都可以帮助我吗? ?**

【问题讨论】:

    标签: php excel laravel import upload


    【解决方案1】:

    假设您使用的是 maatwebsite/excel 包,此链接应该会有所帮助:http://www.maatwebsite.nl/laravel-excel/docs/import#chunk

    您需要将代码更改为以下内容:

    public function uploadNotaCorte(Request $request, EstadoRepository $estadoRepository)
    {
        $error = array();
        $path = $request->file('file')->getRealPath();
    
        Excel::filter('chunk')->load($path)->chunk(100, function($results)
        {
            foreach($results as $row)
            {
                // RULES
            }
        });
    
        return  $error;
    }
    

    这未经测试,我从未使用过该软件包(尽管很高兴知道它存在),因此您的里程可能会有所不同。

    【讨论】:

    • 我已经尝试过这个解决方案,但在我的情况下它不起作用詹姆斯
    猜你喜欢
    • 2017-09-02
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 2021-03-08
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多