<?php

namespace App\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\DummyData as DummyDataModel;
use PDF, Carbon, App;

class PdfDownloadController extends Controller
{
    public function __construct(DummyDataModel $dummyDataModel){
    	$this->dummyDataModel = $dummyDataModel;
    }

    public function index(){
    	return view('frontend.pdf_download');
    }

    public function download(){
    	$this->data['dummy_data'] = $this->dummyDataModel->first();
    	$pdf = App::make('dompdf.wrapper');

    	//set the html view to load
    	$pdf->loadView('domPdf.sample',$this->data);

    	//set the pdf file name
    	//use $pdf->download to download the pdf or use $pdf->stream to display the pdf on your browser
    	return $pdf->download('sample-pdf-'.date('Ymd').'.pdf');
    	// return $pdf->stream('sample-pdf-'.date('Ymd').'.pdf');
    }
}
