芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/panorama.panoramawholesale.com/app/Exports/UserListExport.php
* * @contributor Sabbir Al-Razi <[sabbir.techvill@gmail.com]> * * @created 20-05-2021 */ namespace App\Exports; use App\Models\User; use Maatwebsite\Excel\Concerns\{ FromCollection, WithHeadings, WithMapping }; class UserListExport implements FromCollection, WithHeadings, WithMapping { /** * [Here we need to fetch data from data source] * * @return [Database Object] [Here we are fetching data from User table and also role table through Eloquent Relationship] */ public function collection() { return User::orderBy('id', 'desc')->get(); } /** * [Here we are putting Headings of The CSV] * * @return [array] [Excel Headings] */ public function headings(): array { return [ 'Name', 'Email', 'Role', 'Status', 'Created At', ]; } /** * [By adding WithMapping you map the data that needs to be added as row. This way you have control over the actual source for each column. In case of using the Eloquent query builder] * * @param [object] $userList [It has users table info and roles table info] * @return [array] [comma separated value will be produced] */ public function map($userList): array { return [ $userList->name, $userList->email, $userList->role()->name, ucfirst($userList->status), formatDate($userList->created_at) . ' ' . timeZoneGetTime($userList->created_at), ]; } }