0

I have code to export data to blade template:

namespace App\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class InvoicesExport implements FromView
{
    public function view(): View
    {
        return view('exports.invoices', [
            'invoices' => Invoice::all()
        ]);
    }
}

Where I should place view file exports.invoices?

I tried to place it in path: App\Exports like:

/App/Exports/exports/invoices.blade.php

But Excel can not find this path

2 Answers2

0

The best practice is to place all your views in app/resources/views directory. From there, you can create numerous directories for your needs.

Also, you are using a view() global helper, which by default tries to find views in the directory I mentioned above. This is also explained in Laravel official documentation.

zlatan
  • 3,346
  • 2
  • 17
  • 35
  • What is path? App\Export\Invoices.blade.php? –  Aug 19 '19 at 09:19
  • 1
    `resources/views/exports/invoices.blade.php` it has to be this since the `view()` function will look in for the files in the views folder, `exports.invoices` means that its in a folder called exports while the file is `invoices.blade.php` – Achraf Khouadja Aug 19 '19 at 09:20
  • It can not find this path –  Aug 19 '19 at 09:28
  • What do you mean you can't find this path? There is no app/resources/views directory in your project? – zlatan Aug 19 '19 at 09:29
0

Make a Folder resources/views/exports. You have placed the blade in the wrong directory

Ankush Sood
  • 412
  • 3
  • 13