skip to Main Content

In my case, i have problem like this

Sample table and data :

// Table Account
Id  |  Name  |
 1  |  Kiara |
 2  |  Steve |

My currently code is :

<?php

namespace AppExports;

use MaatwebsiteExcelConcernsFromCollection;
use AppModelsAccount;

class ExportTable implements FromCollection
{
    public function collection()
    {
        return Account::all();
    }
}

What i had now in excel :

 1  |  Kiara |
 2  |  Steve |

I want show the headers value as dynamic as table, without more effort like this

    public function headings(): array
    {
        return [
                "Id",
                "Name"  
        ];
    }

Is it posible?

2

Answers


  1.  public function headings(): array
    {
        return IlluminateSupportFacadesSchema::getColumnListing('tableName');
    
    }
    

    Try this

    Login or Signup to reply.
  2. add your model,

    public function getTableColumns() 
    {
        return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
    }
    

    and …

    public function headings(): array
    {
       $model = new Model();
    
       $columns = $model->getTableColumns();
       return $columns;
    }
    

    try this cok.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search