💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
可能用到的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