This package gives you the ability to create synchronization files and prevent you from having to write one time use commands when you've got for example: A database structure change that will require you to synchronize the old structure data with the new structure.
The best way to install this package is through your terminal via Composer.
Run the following command from your projects root
composer require netcreaties/laravel-synchronize
This package supports package discovery.
Publishing the config will enable you to overwrite some of the settings this package uses. For example you can define where synchronization files should be stored.
php artisan vendor:publish --provider="LaravelSynchronize\Providers\ServiceProvider" --tag="config"
php artisan vendor:publish --provider="LaravelSynchronize\Providers\ServiceProvider" --tag="migrations"
php artisan migrate
Laravel Synchronize executes synchronizations that have the same class name as the migration class name, but with a Synchronization suffix, when executing migrations. This is the advised usage to ensure database integrity, but it is possible to execute synchronizations on their own (see section Synchronize command).
php artisan make:synchronization {name}
Creates the synchronization file at database/synchronizations
php artisan synchronize
It can happen you need a synchronization before you can perform a migration. Using --class and --force can help you achieving that goal.
All you need to do is using the Laravel 5.8.16+ Migration events.
Example:
public function __construct()
{
Event::listen(MigrationStarted::class, function (MigrationStarted $listener) {
if ($listener->migration instanceof $this && $listener->method === 'up') {
Artisan::call('synchronize --class=TestASync --force');
echo Artisan::output();
}
});
}
--force will execute the synchronization even when it already has been run. Use with caution.