-
Excel(엑셀)Laravel/Nova 2021. 12. 4. 14:55반응형SMALL
# What?
라라벨 노바전용 엑셀
# How?
composer require maatwebsite/laravel-nova-excel
* php8이상 쓸 경우
1) php.ini 파일에서 ";extension=gd"를 "extension=gd"로 변경
2) composer require phpoffice/phpspreadsheet
3) composer require maatwebsite/laravel-nova-excel
1. 액션 세팅하기
php artisan nova:action ExportModels
@ ExportModels(extends DownloadExcel, implements WithMapping, withFilename)
<?php namespace App\Nova\Actions; ... class ExportApplications extends DownloadExcel implements WithMapping { use InteractsWithQueue, Queueable; public function map($model): array { $this->withFilename($model->applicationable->title." 지원내역.xlsx"); return [ $model->admin->name, $model->admin->contact, $model->admin->email ]; } }
2. Nova resource에 액션 추가하기(withHeadings)
@ Model.php
... public function actions(Request $request) { return [ (new ExportApplications())->withHeadings("이름", "연락처", "이메일")->canSee(function($date){ return auth()->user()->master; }) ]; }
https://docs.laravel-excel.com/nova/1.x/exports/ 참고
LIST'Laravel > Nova' 카테고리의 다른 글
DateTime(날짜, 시간) 한국어로 변경하기 (0) 2022.03.19 Resource OrderBy(순서) 바꾸는법 (0) 2022.01.13 Advanced Media Library(미디어 라이브러리) (0) 2020.10.15 International DateTime(다국어 지원) (0) 2020.10.15 테마 변경(로고, 색깔 등) (0) 2020.10.14