title: How can you include column headers when exporting Eloquent to Excel in Laravel?
body: <p>I am trying to allow users to download Excel, using <a href="https://laravel-excel.maatwebsite.nl/" rel="noreferrer">Laravel Excel</a> files with product information. My current web route looks like this:</p>
  
  <pre><code>Route::get('/excel/release', 'ExcelController@create')-&gt;name('Create Excel');
  </code></pre>
  
  <p>My current Export looks like this:</p>
  
  <pre><code>class ProductExport implements FromQuery
  {
      use Exportable;
  
      public function __construct(int $id)
      {
          $this-&gt;id = $id;
      }
  
      public function query()
      {
          return ProductList::query()-&gt;where('id', $this-&gt;id);
      }
  }
  </code></pre>
  
  <p>My current controller looks like this:</p>
  
  <pre><code>public function create(Request $request) {
  
      # Only alowed tables
      $alias = [
          'product_list' =&gt; ProductExport::class
      ];
  
      # Ensure request has properties
      if(!$request-&gt;has('alias') || !$request-&gt;has('id'))
          return Redirect::back()-&gt;withErrors(['Please fill in the required fields.'])-&gt;withInput();
  
      # Ensure they can use this
      if(!in_array($request-&gt;alias, array_keys($alias)))
          return Redirect::back()-&gt;withErrors(['Alias ' . $request-&gt;alias . ' is not supported'])-&gt;withInput();
  
      # Download
      return (new ProductExport((int) $request-&gt;id))-&gt;download('iezon_solutions_' . $request-&gt;alias . '_' . $request-&gt;id . '.xlsx');
  }
  </code></pre>
  
  <p>When I head over to <code>https://example.com/excel/release?alias=product_list&amp;id=1</code> this executes correctly and returns an excel file. However, there is no column headers for the rows. The data comes out like so:</p>
  
  <pre><code>1   150 1   3       2019-01-16 16:37:25 2019-01-16 16:37:25     10
  </code></pre>
  
  <p>However, this should contain column headers like ID, cost etc... How can I include the column headers in this output?</p>