php Laravel Excel导出默认表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Laravel Excel导出默认表相关的知识,希望对你有一定的参考价值。

https://docs.laravel-excel.com/3.1/getting-started/installation.html
https://stackoverflow.com/questions/53301568/maatwebsite-laravel-excel-exports-blank-excel-when-using-inputget-in-model
<?php

0) Install Laravel Excell
composer require maatwebsite/excel

1) create Export Controller:
php artisan make:export RegistrationsExport --model=Registration

2) Generated Export Class will look like:

namespace App\Exports;

use App\Registration;
use Maatwebsite\Excel\Concerns\FromCollection;

class RegistrationsExport implements FromCollection
{
  /**
  * @return \Illuminate\Support\Collection
  */
  public function collection()
  {
    return Registration::all();
  }
}


3) RegistrationsController export method:
    /*
    |---------------------------
    | EXCEL EXPORT DEFAULT TABLE
    |---------------------------
    */
    public function export() {
        return Excel::download( new RegistrationsExport(), 'registrations.xlsx') ;
    } 


5) in web.php
    Route::get('registrations/export', 'RegistrationsController@export')->name('registrations.export') ;



6) In Blade View
<a href="{{ route('registrations.export') }}" class="btn btn-dark fright">Export all Registrations <i class="fas fa-download"></a>


















以上是关于php Laravel Excel导出默认表的主要内容,如果未能解决你的问题,请参考以下文章

laravel的excel导出

PHP laravel框架 导入导出excel ,phpexcel数据导出分多个工作区(sheet)

laravel 怎么实现导出execl

使用 laravel 和 vuejs 导出 Excel

laravel5.4 导出 Excel 表格

laravel 5.4 导出excel表格