Laravel Excel - Select columns to export
<p>I'm using Laravel Excel from maatwebsite but i have a problem with export data to xls file. I have this query but i don't need to show all columns in the xls file but i need to select all this columns to do operations before download the file. In my select i have 8 columns but in my headers i just have 7 to show but this doesn't work because the 8ª column appears too.</p>

<p>MY FUNCTION:</p>

<pre><code> public function toExcel($id) { $b = Budget::find($id);

$budget = Budget_Item::join('budgets', 'budget__items.id_budget', '=', 'budgets.id')
    -&gt;join('items_sizes', 'budget__items.id_itemSize', '=', 'items_sizes.id')
    -&gt;join('items', 'items_sizes.id_item', '=', 'items.id')
    -&gt;join('material_types', 'items_sizes.id_materialType', '=', 'material_types.id')
    -&gt;select('items.reference AS Referência', 'items.name AS Descrição', 'items_sizes.size AS Tamanho', 'material_types.material_type AS Material', 'budget__items.amount AS Quantidade', 'items_sizes.unit_price AS Val.Unitário', 'budget__items.price AS Val.Total', 'budget__items.purchasePrice')
    -&gt;where('id_budget', '=', $id)
    -&gt;get();

$budgetUpdate = [];
$budgetUpdate[] = ['Referência', 'Descrição', 'Tamanho', 'Material', 'Quantidade', 'Val.Unitário', 'Val.Total'];
foreach ($budget as $key)
{
  if ($key-&gt;purchasePrice &gt; 0)
  {
    $key-&gt;unit_price = $key-&gt;purchasePrice;
  }

  $budgetUpdated[] = $key-&gt;toArray();
}
Excel::create('Proposta_'.$b-&gt;reference, function($excel) use($budgetUpdated)
{
  // Set the title
  $excel-&gt;setTitle('Proposta');

  $excel-&gt;sheet('Sheetname', function($sheet) use($budgetUpdated)
  {
    $sheet-&gt;fromArray($budgetUpdated, null, 'A1', false, true);
  });

})-&gt;download('xls');}
</code></pre>

<p>How can i solve that?</p>

<p>Thank's</p>