Hertox82 / hardel-Laravel-DbExporter by Hertox82

this is a package for Laravel Framework to export, via command line, Database in Migration and all data in a Seed
909
4
1
Package Data
Maintainer Username: Hertox82
Maintainer Contact: hadeluca@gmail.com (Hernan Ariel De Luca)
Package Create Date: 2017-07-12
Package Last Update: 2018-07-09
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2019-11-16 15:08:51
Package Statistics
Total Downloads: 909
Monthly Downloads: 5
Daily Downloads: 0
Total Stars: 4
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Hardel-Laravel-Exporter

Export your database quickly and easily as a Laravel Migration (for the structure) and all the data as a Seeder class.

This can be done via artisan commands or a controller action.

This package is a restructuring of the existing nWidart/DbExporter library

| Hardel Exporter | Laravel Supported version | MaatWebsite | | :-------------: |:-------------------------:| :---------: | | ^1.0 | 5.4.27 | 2.1.19 | | ^2.0 | 5.4.+, 5.5.+ | 2.1.28 |

Installation

Add "hadeluca/db-exporter"* as a requirement to composer.json:

{
    ...
    "require": {
        ...
		"hadeluca/db-exporter": "^1.0"
    },
}

Update composer:

$ php composer.phar update

or via command line:

$ composer require hadeluca/db-exporter

Add the service provider to app/config/app.php:

'Hardel\Exporter\DBExporterServiceProvider::class'

(Optional) Publish the configuration file.

$ php artisan vendor:publish hadeluca/db-exporter

Use dev-master as version requirement to be on the cutting edge

Documentation

From the commandline

Export database to migration

Basic usage

$ php artisan dbexp:migration

Specify a database

$ php artisan dbexp:migration databaseName

Ignoring tables

You can ignore multiple tables by seperating them with a comma.

$ php artisan dbexp:migration --ignore="table1,table2"

Export database table data to seed class

This command will export all your database table data into a seed class.

$ php artisan dbexp:seed

Also here you can ignore multiple tables:

$ php artisan dbexp:seed --ignore="table1,table2"

Important: This requires your database config file to be updated in config/database.php.

Next all you have to do is add the call method on the base seed class in database/seeds/DatabaseSeeder.php:


$this->call('nameOfYourSeedClass');

Now you can run from the commmand line:

  • php artisan db:seed,
  • or, without having to add the call method: php artisan db:seed --class=nameOfYourSeedClass

Chaining

You can also combine the generation of the migrations & the seed:


$ php artisan dbexp:all [databaseName] [--ignore="table1,table2"]

Ignoring tables

By default the migrations table is ignored.

###Export all data in .xlsx (Excel)

Now you can export all data in excel file from the command line


$ php artisan dbexp:excel-data [databaseName] [path] [--ignore="table1,table2"]

by default (in config.php) you can find the path where the library store the database.xlsx

<?php
return [
    'excel' => [
                'seed' => base_path().'/database/export/excel/seeds/',
                'migrations' => base_path().'/database/export/excel/migration/'
            ]
];

also you can override this path passing path to the commmand line

$ php artisan dbexp:excel-data null ~.Desktop.excelFolder [--ignore="table1,table2"]

automatically you can find in ~/Desktop/excelFolder/database.xlsx

TODO

  • ~~Create export data in excel from MySQL~~
  • Create Postgres Migrator and Seeder
  • Create SQLite Migrator and Seeder
  • Create SqlServer Migrator and Seeder

Credits

Credits to @nicolaswidart for the original package Which I downloaded but was not compatible with the new version of laravel 5.4 and for these reason i modified it.

License (MIT)

Copyright (c) 2017 Hernan Ariel De Luca , hadeluca@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.