Laravel/Nova
Excel(엑셀)
짱구를왜말려?
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/ 참고
🚀 5 minute quick start | Laravel Excel
🚀 5 minute quick start 💡 Require this package in the composer.json of your Laravel project. This will download the package and Laravel Excel. composer require maatwebsite/laravel-nova-excel 1 💪 Go to your Nova resource. As example we'll use the ap
docs.laravel-excel.com
LIST