Download the PHP package coreproc/nova-data-sync without Composer
On this page you can find all versions of the php package coreproc/nova-data-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-data-sync
Laravel Nova Data Sync
This is a Laravel Nova tool to that provides features to import and export CSV files.
Installation
You can install the package in to a Laravel app that uses Nova via composer:
Publish the package's config and migrations:
This package requires Laravel Horizon and comes with the package. If you have not gone through Horizon's install process yet, you can install it by running:
Make sure to configure Horizon's environment processes in config/horizon.php
.
You should also migrate the job batches table:
This package also requires spatie/laravel-media-library and comes with this package. If you have not gone through the installation process of Media Library, you should publish the migrations for it:
Publish Media Library's config file:
Also run the following command to publish the config file for ebess/advanced-nova-media-library:
Usage
Add the tool to your NovaServiceProvider.php
:
The Nova Data Sync tool should now appear in Nova's sidebar.
Importing Data Using a Nova Action
To start with creating an Import feature, you will need two create two classes that extend the following:
- an
ImportProcess
class that contains the validation rules and process logic for each row of an imported CSV file. - and an
ImportNovaAction
class that is essentially a Nova Action
Here is a sample ImportProcessor
:
The rules()
method is where you can define the validation rules for each row of the CSV file. It will be passed the
$row
and $rowIndex
parameters. The $row
parameter is an array of the CSV row's data. The $rowIndex
parameter is
the index. Return an array of Laravel's validation rules.
The expected headers are defined in the expectedHeaders()
method. This is used to validate the headers of the CSV.
The process()
method is where you can define the logic for each row of the CSV file. It will be passed the $row
and
$rowIndex
parameters. The $row
parameter is an array of the CSV row's data. The $rowIndex
parameter is the index.
If you throw an Exception
inside the process()
method, the row will be marked as failed and the exception message
will be shown in the failed report for the Import.
Next, create an ImportNovaAction
class and define the $processor
class you just created.
Next, put your ImportNovaAction
inside the actions()
method of one of your Nova Resources:
It should look something like this:
Using the Import feature without the Nova Action
If you want to use the Import feature without the Nova Action, you can still use your ImportProcessor class. Here is an example of grabbing a file from S3 and importing it:
This will dispatch the jobs necessary to handle the import. You'll also be able to see the progress of the import in the Nova Data Sync tool.
Importing Configuration
You can find configuration options for the Import feature in config/nova-data-sync.php
.
Exporting Data Using a Nova Action
To start with creating an Export feature, you will need two create two classes that extend ExportProcessor
and
ExportNovaAction
.
Here is a sample ExportProcessor
:
You can also format the row data by defining the formatRow()
method:
You can also define the query()
method to return a query builder. This is useful if you want to export data from a
database table.
You can also override methods in the ExportProcessor
class to customize the export process. The following methods can
be overridden:
Next, in order to use it as a Nova Action, create an ExportNovaAction
class and create a processor()
function that
returns the processor class you just created.
If you have additional fields that you want to add to the Export feature, you can define them in the fields()
method
and access them through the $fields
property.
Now, you can add the ExportNovaAction
to your Nova Resource:
User Configuration
Each import and export have a morphable user()
relationship. This is used to determine who imported or exported the
data. You will need to define Nova resource of each user type that you want to use for the import and export features.
This can be done in the config/nova-data-sync.php
file.
By default, this already has the App\Nova\User::class
resource. You can add more user resources like
App\Nova\BackendUser
as needed.
All versions of nova-data-sync with dependencies
anourvalar/eloquent-serialize Version ^1.0
ebess/advanced-nova-media-library Version ^4.1
flatroy/nova-progressbar-field Version ^0.0.6
laravel/horizon Version ^5.21
spatie/laravel-medialibrary Version ^10.0|^11.0
spatie/simple-excel Version ^3.3