how to solve the error when exporting view blade to excel in laravel

98 Views Asked by At

I want to export my view to excel with laravel excel but i get error like this

Failed to load D:\web\cottonello\storage\framework\cache\laravel-excel\laravel-excel-LDIPCoWBtHuyLG2C6xzWafwFdr0Pi4yI.html as a DOM Document

  • I have successfully tested a simple table export, but for the view below, I get an error.

  • I've tested with a simple formula with just one foreach and it works.

I have done php artisan cache:clear, I think this is because there are too many formulas in the view, is there a solution?

my export excel controller

public function view(): View
    {
        return view('dashboard.stock.table',[
            'products' => Product::all(),
            'size' => Size::all(),
            'color' => Color::all(),
            'outlet' => Outlet::all(),
        ]);
    }

view table to export

<table class="table">
    <thead>
      <tr>
        <th>No</th>
        <th>Product</th>
        <th>Color</th>
        <th>Size</th>
        <th>Location</th>
        <th>Stock</th>
      </tr>
    </thead>
    <tbody>
        @foreach ($products as $product)
        <tr>
            <td rowspan={{ $color->count() * $size->count() }}>{{ $loop->iteration }}</td>
            <td rowspan={{ $color->count() * $size->count() }}>{{ $product->name }}</td>
            <td rowspan={{ $size->count() }}>{{ $color[0]->name }}</td>
            <td>{{ $size[0]->size }}</td>
            <td rowspan={{ $color->count() * $size->count() }}>Location : TSM, Nuris, Samasta, Ubud</td>
            <td>-Input Stok-</td>
            @foreach ($size->skip(1) as $item)
                <tr>
                    <td>{{ $item->size }}</td>
                    <td>-Input Stok-</td>
                </tr>
            @endforeach
            @foreach ($color->skip(1) as $item)
                <tr>
                    <td rowspan={{ $size->count() }}>{{ $item->name }}</td>
                    <td>{{ $size[0]->size }}</td>
                    <td>-Input Stok-</td>
                    @foreach ($size->skip(1) as $item)
                        <tr>
                            <td>{{ $item->size }}</td>
                            <td>-Input Stok-</td>
                        </tr>
                    @endforeach
                </tr>
                
            @endforeach
            
        </tr>
        @endforeach
    </tbody>
</table>

route

Route::get('/dashboard/stock/table', [templateImport::class, 'view']);

stock controller

public function template_export(){
        return FacadesExcel::download(new templateImport, 'template.xlsx');
    }
0

There are 0 best solutions below