Export Classes¶
Export classes are the main way to use the package. Each export class implements at least FromWordTemplate and optionally other concerns (GlobalTokens, TokensFromCollection, WithCharts, etc.).
Required: FromWordTemplate¶
Every export class must implement FromWordTemplate, which defines the Word template file:
Return a path relative to storage_path() or an absolute path. See Template Resolution.
Creating an export class¶
Use the Artisan command:
Replace {ClassName} with the name of your export class (e.g. InvoiceExport). The class is created in your application (e.g. app/Http/Export/).
WordExport facade¶
Use the WordExport facade to run exports. The output format is determined by the file extension you pass.
download($export, $fileName)¶
Returns an HTTP response that triggers a file download.
WordExport::download(new MyExport(), 'export.docx');
WordExport::download(new MyExport(), 'export.pdf'); // requires LibreOffice
store($export, $filePath)¶
Saves the exported file to the given path. Filename is generated.
storeAs($export, $filePath, $name)¶
Saves with a specific filename.
queue($export, $filePath)¶
Dispatches a job to generate the file asynchronously.
batchStore(...$exports)¶
Stores multiple exports. Each argument must be an Santwer\Exporter\Exportables\Exportable instance wrapping the export class, path, and filename.
use Santwer\Exporter\Exportables\Exportable;
WordExport::batchStore(
new Exportable(new MyExport1(), 'exports/', 'one.docx'),
new Exportable(new MyExport2(), 'exports/', 'two.pdf'),
);
See Batch & Queue for details.