PHP code example of mreycode / laravel-db-migrator
1. Go to this page and download the library: Download mreycode/laravel-db-migrator 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/ */
mreycode / laravel-db-migrator example snippets
namespace App\DbMigrators;
use Mreycode\DbMigrator\AbstractDbMigrator;
use App\Models\User;
class UserMigrator extends AbstractDbMigrator
{
/** @var string The column name representing the unique ID in the source data */
public $migratorSourceId = 'source_id';
/** @var string The column name representing the unique ID in the target table */
public $migratorTargetId = 'id';
/** @var bool Set to true to store the source-to-target ID mapping in the history table */
public bool $recordMigratorHistory = false;
public function sourceData()
{
return $this->getSourceConnection()
->table('legacy_users')
->offset($this->getOptions()['offset'])
->limit($this->getOptions()['limit'])
->get();
}
public function handle($params = null)
{
foreach ($params['sourceData'] as $row) {
User::create([
'name' => $row->full_name,
'email' => $row->email,
]);
}
}
}