Laravel-snappy and many different views

Posted 4 months ago by cemcminn

I have an entire directory of letters (with data) that I have made into views. My plan was to use the tutorial at laravelcode.com (link below) to build a generic Controller that would process any view I want to send to it:

https://laravelcode.com/post/html-to-pdf-in-laravel-using-barryvdh-laravel-snappy

My current code (I have removed the 'data search pieces' at present)

class PdfGenerateController extends Controller
{
    public function pdfview(Request $request)
    {
        if($request->has('download')) {
            // pass view file
            $pdf = PDF::loadView('emails.app_ack.index');
            // download pdf
            return $pdf->download('app_ack.pdf');
        }
        return back();
    }

}

The tutorial shows building the data from one source by finding it again in the above method call and it works for the first document I tried, but I won't always need just that one table. Any thoughts on how I might pass in all the data I need from the view so that it builds any page I might ask for?

Would it be better to use the 'wrapper' method and perhaps create 2 versions of each page (one for display and one for pdf download?)

Am I completely on the wrong path?

Thank you.

Please sign in or create an account to participate in this conversation.