1. Go to this page and download the library: Download padocia/laravel-nova-pdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
padocia / laravel-nova-pdf example snippets
namespace App\Nova\Actions;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Laravel\Nova\Fields\ActionFields;
use Padocia\NovaPdf\Actions\ExportToPdf;
class InvoiceAction extends ExportToPdf
{
/**
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
*
* @return \Illuminate\View\View
*/
public function preview(ActionFields $fields, Collection $models) : View
{
$resource = $this->resource;
return view('nova-pdf.template', compact('models','resource'));
}
}
namespace App\Nova;
use Illuminate\Http\Request;
use App\Nova\Actions\InvoiceAction;
class User extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\\User';
// Other default resource methods
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [
new InvoiceAction,
];
}
}
protected function handleBrowsershotOptions()
{
$this->browsershot = $this->browsershot->format('A4');
return $this;
}
protected function filename()
{
return "your_new_filename.pdf";
}
$this->withDisk('public');
$this->addStyle('nova_style_name');
$this->useTailwind(false);
protected $downloadUrlExpirationTime = 1; // 1 min