Calling facades from the controller - laravel 5.6

-1

I'm trying to build an api rest in laravel 5.6, the api has to generate a pdf for that I'm using the DomPDF library, and probe from the web routes and it works well but when I try to do it in a controller it does not work for me that does not find the facade "PDF". Here I leave you a piece of code thanks in advance.

<?php

namespace App\Http\Controllers;

//use App\PDF;
use Illuminate\Http\Request;

class PdfController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $pdf = PDF::loadView('vista');
        return $pdf->download('carta.pdf');
        //return view('vista');
    }}

the error you give me is this

  

"Class 'App \ Http \ Controllers \ PDF' not found"

I think you're asking me to include the path where this PDF is but if it's a facade it should not work anywhere without calling it?
THANKS IN ADVANCE.

    
asked by Frank Campos Vilchez 17.08.2018 в 19:41
source

1 answer

0

If configured correctly, only the class is imported using the alias at the top of the class:

use PDF;

What happens is that when you are configuring this library and you add the facade in the array of aliases within the file config/app.php what it really does is to avoid the trouble of writing all this: use Barryvdh\DomPDF\Facade::class , and well, this facade it works like a proxy, accessing the underlying implementation of the interface.

    
answered by 17.08.2018 / 19:47
source