ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
可能用到的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