0

I am using laravel-excel 3.0 in my laravel project and i am unable to create drop-down list while downloading the list.

Below is Export class code

 class MasterFields implements FromView
 {
    public function view(): View
{
    return view('master-fields', [
        'master_fields' =>  [
            [
              'name' => 'Povilas',
              'surname' => 'Korop',
              'email' => 'povilas@laraveldaily.com',
              'twitter' => ['@povilaskorop', 'test', 'test']
            ],
            [
              'name' => 'Taylor',
              'surname' => 'Otwell',
              'email' => 'taylor@laravel.com',
              'twitter' => ['@povilaskorop', 'test', 'test']
            ]
          ]
        // MasterDataField::get_master_data_set()
    ]);
  }
  }

Below is blade code

<table>
    <thead>
       <tr>
         <th style="color:blue;"><b> ID </b></th>
         <th style="color:blue;"><b> Field Name </b></th>
         <th style="color:blue;"><b> Data Type </b></th>
     </tr>
  </thead>
 <tbody>
     @foreach($master_fields as $field)
    <tr>
        <td>{{ $field['name'] }}</td>
        <td>{{ $field['surname'] }}</td>
        <td>
            <select>
                @foreach($field['twitter'] as $twitter)
                <option> {{ $twitter }} </option>
                @endforeach
            </select>


         </td>
     </tr>
     @endforeach
   </tbody>

I am using below method to download return Excel::download(new MasterFields, 'test.xlsx');

enter image description here

Juluri Vinay
  • 105
  • 3
  • 14
  • Possible duplicate of [Laravel excel library(Maatwebsite) : How to create a drop down list in exports](https://stackoverflow.com/questions/29815227/laravel-excel-librarymaatwebsite-how-to-create-a-drop-down-list-in-exports) – Denis Jul 22 '19 at 14:09
  • I am using 3.0 version and the create method was deprecated. Can you plz suggest me with the latest version of mattwebsite laravel-excel – Juluri Vinay Jul 22 '19 at 14:12

1 Answers1

0

As you mentioned the old way of definition doesn't work. But here is an example of the new way: https://laraveldaily.com/laravel-excel-3-0-export-custom-array-excel/

Denis
  • 400
  • 1
  • 12
  • I have coded the same but, i am unable to create a dropdown – Juluri Vinay Jul 22 '19 at 14:20
  • Can you show us what is the response of : MasterDataField::get_master_data_set() – Denis Jul 22 '19 at 14:21
  • [{id: 1, field_name: 'amount' }, {id: 1, field_name: 'description' }, ....] – Juluri Vinay Jul 22 '19 at 14:24
  • Everything looks fine. Can you try with the array from the link instead of calling get_master_data_set() just to be sure it's not about data format – Denis Jul 22 '19 at 14:30
  • Cell values are affecting in excel with my code, but when I try to create a dropdown for a cell it is not coming – Juluri Vinay Jul 23 '19 at 10:58
  • Have you tried by replacing the get_master_data_set() with the array from the link just to make sure the array structure is correct? Do you see an exception? Can you show us the result in that excel file? – Denis Jul 23 '19 at 11:21
  • Yes I have tried by replacing and I have updated the all my code and excel response in the image above, please check. – Juluri Vinay Jul 24 '19 at 07:33
  • Ah I see, can you try instead of select with unordered list https://www.w3schools.com/tags/tag_ul.asp – Denis Jul 24 '19 at 08:24
  • Ya tried that as well. But giving same result, but not populating as dropdown box. – Juluri Vinay Jul 24 '19 at 09:34