Laravel-调用未定义的方法Maatwebsite\Excel\Excel::create()
尽管我在config/app.php中添加了服务提供者和别名,但仍然会出现此错误 Controller.phpLaravel-调用未定义的方法Maatwebsite\Excel\Excel::create(),laravel,laravel-5,Laravel,Laravel 5,尽管我在config/app.php中添加了服务提供者和别名,但仍然会出现此错误 Controller.php public function export_app_csv(){ $data = Item::get()->toArray(); return Excel::create('test_export', function($excel) use ($data) { $excel->sheet('mySh
public function export_app_csv(){
$data = Item::get()->toArray();
return Excel::create('test_export', function($excel) use ($data) {
$excel->sheet('mySheet', function($sheet) use ($data)
{
$sheet->fromArray($data);
});
})->download('xlsx');
}
/*
* Package Service Providers...
*/
Maatwebsite\Excel\ExcelServiceProvider::class,
/* aliases */
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
config/app.php
public function export_app_csv(){
$data = Item::get()->toArray();
return Excel::create('test_export', function($excel) use ($data) {
$excel->sheet('mySheet', function($sheet) use ($data)
{
$sheet->fromArray($data);
});
})->download('xlsx');
}
/*
* Package Service Providers...
*/
Maatwebsite\Excel\ExcelServiceProvider::class,
/* aliases */
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
控制器中的方法只是一个站点示例。因为我仍然不知道laravel excel是如何工作的
接着,我又遇到了更多的问题
namespace App\Exports;
class InvoicesExport implements FromCollection
{
public function collection()
{
return Invoice::all();
}
}
上面的代码为我提供了“App\FromCollection”未找到的界面,如果您正确地遵循文档,这将起作用
public function get_export_csv(){
$allData = $this->data->get();
$module = $this->module;
Excel::create('projects', function($excel) use ($allData, $module) {
$excel->sheet('sheet1', function($sheet) use ($allData, $module) {
$sheet->loadView('admin.'.$this->module.'.excel', compact('allData','module'));
});
})->download('csv');
}
在你的刀刃上,你只需要这张桌子
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
</tr>
</thead>
<tbody>
<?php $count = 0; ?>
@foreach($allData as $row)
<?php $count++; ?>
<tr>
<td>{{$count}}</td>
<td>{{$row->first_name}}</td>
</tr>
@endforeach
</tbody>
</table>
#
名字
@foreach($allData作为$row)
{{$count}}
{{$row->first_name}
@endforeach
这不是寻求帮助的方式,请向我们展示您迄今为止所做的工作。这包括你是如何做到的。你能给我们一些关于它的更多信息吗?发布你的代码和错误行请检查编辑过的问题。我更喜欢使用loadView(),因为它比fromArray()快。。。如果您想了解fromArray()的工作原理,请检查此链接,我在使用Excel::create()调用未定义的方法Maatwebsite\Excel\Excel::create()my composer.json“Maatwebsite/Excel”:“^3.1”、“phpoffice/phpspreadsheet”:“^1.17”时遇到了类似这样的错误,有什么线索吗?