🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
可能用到的laravel命令行: ``` php artisan make:controller ExportExcelController php artisan make:migration create_exports_table --create=exports ``` 方法1: ``` <?php namespace App\Exports; use App\Media; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\FromView; class MediasExport implements FromView { public function view(): View { $medias = Media::where('user', '1')->orderBy('created_at', 'asc')->get(); // desc, asc return view('export', compact('medias')); } } ``` 方法2: ``` <?php namespace App\Exports; use App\Media; use Maatwebsite\Excel\Concerns\FromCollection; class MediasExport implements FromCollection { /** * @return \Illuminate\Support\Collection */ public function collection() { return Media::where('display_status', '1')->orderBy('created_at', 'asc')->get(); // asc, desc } } ``` 参考: https://github.com/Maatwebsite/Laravel-Excel