Hola he estado intentando exportar desde un view usando laravel-excel maatwebsite
, un registro que muestro en una tabla pero la verdad no comprendo muy bien que es lo que debo hacer, ya que al tratar de exportar me aparece el siguiente error
En todos los ejemplos que he investigado veo que usan el ::all() en el Export pero ahi trae todos los registro y yo solo necesito un registro.
Aqui adjunto mi estructura:
GasolinaExport.php
<?php
namespace App\Exports;
use App\Models\Gas;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView
class GasolinaExport implements FromView{
protected $view;
protected $data;
public function __construct($view, $gas){
$this->view = $view;
$this->gas = $gas;
}
public function view(): View{
return view($this->view,
$this->gas);
}
}
export.blade.php
@extends('layouts.plantilla')
@section('title', 'Gasolina')
@section('content')
<div class="p-5 rounded">
<h1>Exportacion</h1>
<p class="lead">Use el menu superior para entrar en las opciones que desea.</p>
</div>
<div class="container">
<table class="table table-bordered">
<caption>Informe de Combustible {{ \Carbon\Carbon::parse($gas->fecha)->format('d/m/Y')}}</caption>
<tr>
<th></th>
<th>95</th>
<th>91</th>
<th>Diesel</th>
<th>Total</th>
</tr>
<tr>
<th>Efectivo</th>
<td>{{$gas->efectivo_95}}</td>
<td>{{$gas->efectivo_91}}</td>
<td>{{$gas->diesel_efectivo}}</td>
<td>{{($gas->efectivo_95 + $gas->efectivo_91 + $gas->diesel_efectivo)}}</td>
</tr>
<tr>
<th>Cheque</th>
<td>{{$gas->cheque_95}}</td>
<td>{{$gas->cheque_91}}</td>
<td>{{$gas->diesel_cheque}}</td>
<td>{{($gas->cheque_95 + $gas->cheque_91 + $gas->diesel_cheque)}}</td>
</tr>
<tr>
<th>Tarjeta</th>
<td>{{$gas->tarjeta_95}}</td>
<td>{{$gas->tarjeta_91}}</td>
<td>{{$gas->diesel_tarjeta}}</td>
<td>{{($gas->tarjeta_95 + $gas->tarjeta_91 + $gas->diesel_tarjeta)}}</td>
</tr>
</table>
</div>
@endsection
GasolinaController.php
public function export(Gas $gasolina)
{
return Excel::download(new GasolinaExport('gasolina.export', $gasolina), 'gas.xlsx');
}