1. Go to this page and download the library: Download nicklayb/laravel-db-import library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicklayb / laravel-db-import example snippets
namespace Foo\Console\Commands;
use Nicklayb\LaravelDbImport\Import;
class ProdImport extends Import
{
protected $sourceConnection = 'source';
protected $destinationConnection = 'mysql';
}
namespace Foo\Console\Commands;
use Nicklayb\LaravelDbImport\Import;
class ProdImport extends Import
{
protected $sourceConnection = 'source';
protected $destinationConnection = 'mysql';
public function manipulateUsers($user)
{
$user->created_at = Carbon::now();
return $user;
}
}
return [
/**
* Register your databases imports class here by specifying a key
* and the class to manage this import
*
* 'production' => Namespace\ProductionImport::class
*/
'imports' => [
'prod' => Foo\Console\Commands\ProdImport::class
]
];
class MyImport extends Import
{
/**
* The key of the source connection created in the database config file
*
* @var string
*/
protected $sourceConnection = 'source';
/**
* The key of the destination connection created in the database config file
*
* @var string
*/
protected $destinationConnection = 'destination';
/**
* Password reset option, yout must specify the table of the users as
* key and specify the new password as the value. Default column
* is 'password' but override it by adding :column
* 'users:column_password' => 'superpassword'
*
* @var array
*/
protected $resetPassword = [];
/**
* Specify tables you don't want to import during the upload by specifying
* the table name
*
* @var array
*/
protected $ignoreTables = [];
/**
* Set the tables to import after all the others, this is useful when you
* are dealing with foreign key constraints
*
* @var array
*/
protected $lastTables = [];
/**
* Set this property to true to execute a php artisan migrate:refresh
* before importing your database
*
* @var bool
*/
protected $refresh = false;
/**
* Specify table by table the select statement of which column to load like
* ['users' => ['firstname', 'lastname']]
*
* @var array
*/
protected $selects = [];
/**
* Show table command, it may change depending on your database server
*
* @var string
*/
protected $showTablesCommand = 'SHOW TABLES';
/**
* Key for default password when using reset passwords
*
* @var string
*/
protected $defaultPasswordColumn = 'password';
/**
* Method that hashes password
*
* @param string $password
* @return string
*/
public function hashPassword($password)
{
return bcrypt($password);
}
/**
* Fill the array with Closures to execute before starting the import
*
* @return array
*/
public function preImport()
{
return [];
}
/**
* Fill the array with Closures to execute after the import is done
*
* @return array
*/
public function postImport()
{
return [];
}
}
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.