如何解决如何在 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 几个字段...稍后我将需要编写导入功能以在导出文件中生成...
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。