mardi 15 juin 2021

Laravel excel library(Maatwebsite) : How to create a drop down with FromArray Export

I'm using Laravel Excel to export excel with larvel. I need a dropdown for a specific column.

My export file,

use App\MyModel;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;

class MyModelExport implements FromArray, WithHeadings
{
    public function array(): array
    {
        $branches = MyModel::get([
            "title",
        ]);

        $data = [];
        $districts = [
           '1' => 'Dis 1',
           '2' => 'Dis 2',
        ];

        foreach ($items $key => $item) {

            $data[$key]['title'] = $item->title;
            $data[$key]['districts'] = $districts;
        }

        return $data;
    }

    public function headings(): array
    {
        return [
            'Title',
            'Districts'
        ];
    }
}

What I need is to add these $districts as a dropdown inside excel. Is there a way to do it?(Sadly this code only prints all array values in single cell)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire