laravel - 如何使用 maatwebsite excel 导出相关表中的数据?
问题描述
在带有 "maatwebsite/excel": "^3.1" 的 Laravel 8 中,我使用某些枚举列必须具有标签而不是枚举值的功能导出表行,例如:
public function collection()
{
$adsIdList = [7,1,5];
return Ad
::getById($adsIdList)
->get()
->map(function ($adItem) {
$a = Carbon::createFromFormat('Y-m-d', $adItem->expire_date);
$is_past = $a->isPast();
$retAdItem = [
'id' => $adItem->id, // A
'title' => $adItem->title, // B
'slug' => $adItem->slug, // C
'phone_display' => $adItem->phone_display ? 'Y' : 'N', // D
'has_locations' => $adItem->has_locations ? 'Y' : 'N', // E
'status' => Ad::getStatusLabel($adItem->status), // F
'price' => $adItem->price, // G
'ad_type' => Ad::getAdTypeLabel($adItem->ad_type), // H
'expire_date' => $adItem->expire_date, // I
'is_past' => $is_past, // ?
我还在上面的 app/Exports/AdsExport.php 文件中添加了一些计算字段。
但是如果有办法从相关表中添加数据呢?任何广告都可以有多个带有多个字段的 ad_locations...稍后我将需要编写导入功能以在导出文件中生成...
谢谢!
解决方案
推荐阅读
- python-3.x - 在 python 中创建对象并与其他对象分离
- sql-server - 为什么“如果不存在”在维护计划中不起作用?
- python - Celery 任务在没有 celerybeat 的情况下成功后调用自身
- sql-server - 使用 SQL Server/ADO 替代 Index + Seek on Access/DAO
- javascript - 根据条件数组递归过滤对象数组
- spring - Tomcat 7 启动失败并出现 srpingboot
- python - Django:无法使用命令上传带有西班牙语字符的数据
- javascript - 未捕获的 SyntaxError: missing ) 在 codeigniter 中的参数列表之后
- python - 匹配给定字符集的幂集中任何内容的正则表达式
- c# - 如何使用动态列名查找重复行?