PHP code example of samody / laravel-migration-preflight
1. Go to this page and download the library: Download samody/laravel-migration-preflight 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/ */
samody / laravel-migration-preflight example snippets
return [
'strict' => true,
'checks' => [
'missing_tables' => true, // Check for missing tables
'missing_columns' => true, // Check for missing columns
'foreign_keys' => true, // Check foreign key references
'index_constraints' => true, // Check index constraints
'unique_constraints' => true, // Check unique constraints
],
];
// Automatically pluralizes table name
$table->foreignId('user_id')->constrained(); // Looks for 'users' table
// Explicit table name
$table->foreignId('owner_id')->constrained('users');
// Manual foreign key
$table->foreign('customer_id')->references('id')->on('customers');
// Single column index
$table->index('email');
// Unique constraint
$table->unique('email');
// Multi-column unique
$table->unique(['email', 'username']);
// Full-text index
$table->fullText(['title', 'description']);
// Spatial index (MySQL)
$table->spatialIndex('coordinates');
$table->string('email')->after('name'); // Column must exist
$table->dropColumn('old_field'); // Column must exist
$table->renameColumn('old_name', 'new_name'); // Column must exist
$table->string('email')->change(); // Column must exist
Schema::table('users', function ($table) { // Table must exist
$table->string('new_field')->default('N/A');
});
bash
php artisan migrate:preflight
bash
php artisan migrate:preflight --verbose
bash
php artisan vendor:publish --tag=preflight-config
bash
#!/bin/bash
php artisan migrate:preflight
if [ $? -ne 0 ]; then
echo "❌ Migration validation failed!"
exit 1
fi
echo "✅ All migrations validated successfully"