Ever needed to copy selected models between server environments? Or seed a database with latest content?
This package exports models to S3 or other remote disks as a JSON file.
Just a tool to move content based models between different environments without any hassle.
Install the package via composer:
composer require ekoukltd/s3-import-export
Publish the config file to config/s3-import-export.php
php artisan vendor:publish --provider="Ekoukltd\S3ImportExport\S3IOServiceProvider" --tag="config"
and define which what should be exported to where. For S3 you need to have setup league/filesystem see: https://laravel.com/docs/9.x/filesystem#s3-driver-configuration
//Data will be exported to this disk -> choose from config.filesystems.disks options
//Note that if using s3 a local copy will also be created in storage when importing
//When running tests local storage copy will be used.
'disk' => 's3',
//Where to stick em. Note trailing slash
'export_dir' => 'content-export/',
//Add your models to import and export here
'content_models' => [
//Json object exports are ideal for copying content type data like pages, posts and templates
//without affecting the reset of the database
'App\\Models\\Pages',
'App\\Models\\Posts',
'App\\Models\\EmailTemplates',
],
/** IMPORTANT **/
//Carbon dates export with a timezone by default, which throws an error when importing to sql
//If your using timestamps either set any other date fields here
'date_columns' => ['created_at', 'updated_at', 'deleted_at']
//or set the format in the model
protected $casts = [
'email_verified_at' => 'datetime:Y-m-d H:i:s'
'my_date_field' => 'datetime:Y-m-d H:i:s',
];
#Export from the CLI
php artisan data:export
#Import
php artisan data:import
#Or in a scheduled task:
Artisan::call('data:export');
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email support@ekouk.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.