Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel excel中导入基础知识_Php_Excel_Laravel - Fatal编程技术网

Php 在laravel excel中导入基础知识

Php 在laravel excel中导入基础知识,php,excel,laravel,Php,Excel,Laravel,我试图了解如何使用laravel/excel导入我的excel文件 我试着这样做: public function import() { $path = public_path(); Excel::load($path.'/file.xlsx', function($reader) { $firstrow = $reader->first()->toArray(); dd($firstrow)

我试图了解如何使用laravel/excel导入我的excel文件

我试着这样做:

public function import()
    { 
        $path = public_path();
        Excel::load($path.'/file.xlsx', function($reader) {

            $firstrow = $reader->first()->toArray();
            dd($firstrow);

        });
    }
但是当我扔掉任何东西时,不要从拉威尔那里得到任何垃圾

这是我的excel中的数据:

item    spool   junta
1       test1   j1
2       test2   j2
3       test3   j3
是一个简单的文件只是为了测试,但什么也没有发生,我只是得到一个没有我的转储空白页


提前感谢您的帮助

您可以使用以下代码加载此.xls文件:

$post = new your_modelname;

$post-> Excel::load('your_sheet.xls', function($reader) {

$reader->setDateColumns(array(
    'created_at',           // for timestamp
    'updated_at' ));

})->get();

试试这个,希望它能起作用。

这就是我导入文件的方式,它可以完美地工作

$file = $request->file('userfile');

Excel::load($file, function($reader)
{
foreach ($reader->toArray() as $row) 
{
dd($row);
// fire your query here to insert data to db...
}
}