Laravel 5 vsmoraes/laravel-pdf

I'm trying to use vsmoraes/laravel-pdf and follow the steps but i'm a little confused because i don't know where I should add this? :

$router->get('/pdf/view', function() {
    $html = view('pdfs.example')->render();

    return PDF::load($html)->show();
});

I add a prefix in my "route" so I can redirect in this case:

Route::group(['prefix'=> 'admin'], function(){
    Route::resource('impresion', 'ImpresionController');

});

and my controller "ImpresionController" I have this:

public function index()
    {
        return view('admin.impresion.index');
    }

so in my browser I add this URL:

localhost:8000/admin/impresion.

I really appreciate if you can help me.

Upvotes: 0

Views: 952

Answers (1)

Yurich
Yurich

Reputation: 577

I think, this is all what you need

<?php namespace App\Http\Controllers;

use Vsmoraes\Pdf\Pdf;

class ImpresionController extends BaseControler
{
    private $pdf;

    public function __construct(Pdf $pdf)
    {
        $this->pdf = $pdf;
    }

    public function index()
    {
        $html = view('admin.impresion.index')->render();

        return $this->pdf
            ->load($html)
            ->show();
    }
}

look at the very bottom github

Upvotes: 1

Related Questions