Download the PHP package redsquirrelstudio/laravel-backpack-export-operation without Composer
On this page you can find all versions of the php package redsquirrelstudio/laravel-backpack-export-operation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redsquirrelstudio/laravel-backpack-export-operation
More information about redsquirrelstudio/laravel-backpack-export-operation
Files in redsquirrelstudio/laravel-backpack-export-operation
Package laravel-backpack-export-operation
Short Description An operation to make configurable exports for your CRUDs using the Backpack api you know and love
License MIT
Informations about the package laravel-backpack-export-operation
Export Operation for Backpack for Laravel
Adds a configurable interface that allows your admin users to:
- Export CRUD resources to multiple file formats.
- Decide which columns they would like to export.
and allows you as the developer to:
- Customise each CRUD's export behaviour using the Backpack API you know and love.
- Choose between queued or instant exports.
- Completely customise the operation's behaviour.
If you're looking for a great team of developers to handle some Backpack/Laravel development for you, drop us a line at Sprechen
Also need imports for your CRUD? Check out redsquirrelstudio/laravel-backpack-import-operation
Powering the exports in the background is
Table of Contents
- Installation
- Usage
- Disabling User Configuration
- Queued Exports
- Configuration
- File Storage
- Queues
- Changing the Export log Model
- Customising Translations
- Customising Views
- Export Completed Event
- Restricting Access
- Credits
- License
Installation
Environment Requirements
- PHP extension php_zip
- PHP extension php_xml
- PHP extension php_gd2
- PHP extension php_iconv
- PHP extension php_simplexml
- PHP extension php_xmlreader
- PHP extension php_zlib
Step 1.
Require the package with composer:
This will also install if it's not already in your project.
Step 2. (Optional)
If you would like to add the option to export PDFs, you should also install dompdf:
Step 3. (Optional)
The service provider at: will be auto-discovered and registered by default. Although, if you're like me, you can add it to your .
Step 4.
Publish the config file:
This will create a new file at allowing you to customise things such as the disk and path exported files should be stored at.
Step 5.
Publish and run the migration:
Then
Usage
In your CRUD Controller where you need the export operation.
Wait for it...
Add the export operation:
But wait! There's more!
Configuring the Export
Configuring the export is exactly the same as how you would configure the list operation. Simply define which columns you would like to export, here's an example:
Pretty much all columns that are available for the list operation will work fine in an export. This also means you can define your own columns in the exact same way as you would with list columns.
For a list of available column types, see Backpack for Laravel's Documentation
Disabling User Configuration
Sometimes, you may not want the user to be able to choose which columns are included in their export, In these cases, you can disable the user configuration step.
To enable this behaviour, add this one line of code to the function:
Queued Exports
In most situations, it is going to be better for the user if your exports are processed in the background rather than making them wait for the export to finish processing.
Therefore, you have the option to queue your exports by adding this line of code to the function:
When this option is enabled, you will need to handle what happens when the export finishes or the user will not receive their export. To do this, you should handle the using an event listener. This event contains the export log which you can get the file path from to send to the user via email, notification etc.
Read about the export complete event here
Learn how to handle events on Laravel's official Docs
Of course, for this to work, you will need to set up a queue for your application to dispatch jobs to, to do that, follow Laravel's official docs.
When this setting has been enabled, the user will be redirected to the current CRUD's list view. An alert will appear in the top right which has a default message.
If you would like to change this message, add the following line to the function:
Configuration
File Storage
By default, export files will be stored in your default disk at the path /exports. but this can be altered either by changing the following env variables:
Or by directly changing the options within .
Queues
You can also change the queue that queued exports are dispatched to by changing the following env variables:
or changing the value directly within .
Export Log
In very rare cases, you may wish to also change the model that is used to log exports, I can't think of a reason why, but I'm sure someone will come up with one.
If you do, make sure to update the migration, and specify your own model at .
Translations
You can update the operation translations if required. To do this run:
this will publish the operation lang files to The files stored in this directory take priority over the package's default lang files.
Views
You can update the operation views if required. To do this run:
this will publish the operation blade files to The files stored in this directory take priority over the package's default views.
Export Completed Event
This package fires an event when an export has been completed. The event payload contains the export log so that you can send an email, notification or whatever else with a download url for the file.
Event Class:
Payload:
Restricting Access
Like most operations in Backpack, you can restrict user access using the following line of code in your CRUD Controller's setup function:
Credits
- Lewis Raggett and The Team at Sprechen :: Package Creator
- Cristian Tabacitu :: Backpack for Laravel Creator
- Spartner :: Laravel Excel Creator
- DomPDF :: DOMPDF Creator
License
MIT. Please see the license file for more information.