首页 > 解决方案 > 如何在 Laravel 中使用选择列表导出 Excel

问题描述

任何人都可以告诉我如何使用此图像的选择列表导出 Excel 文件在此处输入图像描述

我的要求与这些照片相同,我只想在 excel 文件中提供角色选择下拉菜单。

为此,我正在使用 Laravel 的 Maatwebsite 插件。

这是我的示例代码...

<?php

namespace App\Exports;

use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class UserRoles implements FromCollection, WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return User::with(['roles'])->get();
    }

    public function headings(): array
    {
        return ['id','name','email','role'];
    }
}

如果有人可以帮助我,谢谢。

标签: phpexcellaravelvue.jsmaatwebsite-excel

解决方案


推荐阅读