PHP code example of sirval / laravel-smart-migrations
1. Go to this page and download the library: Download sirval/laravel-smart-migrations 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/ */
sirval / laravel-smart-migrations example snippets
return [
// Default model namespace for model resolution
'model_namespace' => 'App\\Models',
// Require user confirmation before rollback
'rollback' => true,
// Enable audit logging for rollbacks
'audit_log_enabled' => false,
// Table name for audit logs
'audit_log_table' => 'smart_migrations_audits',
];
use Sirval\LaravelSmartMigrations\Facades\SmartMigrations;
// Rollback by table
$results = SmartMigrations::rollbackTable('users', ['latest' => true]);
// Rollback by model
$results = SmartMigrations::rollbackModel('User', ['latest' => true]);
// Rollback by batch
$results = SmartMigrations::rollbackBatch(5);
// List migrations for table
$migrations = SmartMigrations::listMigrationsForTable('users');
// List migrations for model
$migrations = SmartMigrations::listMigrationsForModel('User');
// Get table status
$status = SmartMigrations::getTableStatus('users');
// Get model status
$status = SmartMigrations::getModelStatus('User');
$options = [
'latest' => true, // Rollback latest only
'oldest' => false, // Rollback oldest only
'all' => false, // Rollback all
'batch' => null, // Specific batch number
'force' => false, // Skip confirmation
'dry_run' => false, // Preview without executing
];
SmartMigrations::rollbackTable('users', $options);