A standalone tool for comparing Laravel Eloquent models with database schema and generating migrations.
- 🔍 Model-Database Comparison: Compare your Laravel models with the actual database schema
- 🔧 Automatic Fixes: Automatically update model
$fillableproperties - 📋 Migration Generation: Generate Laravel migrations for missing tables and columns
- 💾 Database Backup: Create automatic backups before running migrations
- 🌍 Environment Aware: Works in DDEV, Docker, and local PHP environments
- 📊 Multiple Output Formats: JSON output support for CI/CD integration
- Download or clone this repository
- Copy the entire
laravel-schema-checkerfolder into your Laravel project root - Make the scripts executable:
chmod +x laravel-schema-checker/check.php chmod +x laravel-schema-checker/run-checker.sh
cd your-laravel-project
git clone https://github.com/your-repo/laravel-schema-checker.git
cd laravel-schema-checker
chmod +x check.php run-checker.sh# Compare models with database schema
php laravel-schema-checker/check.php
# Fix model fillable properties automatically
php laravel-schema-checker/check.php --fix
# Preview changes without applying them
php laravel-schema-checker/check.php --dry-run
# Generate Laravel migrations for missing tables/columns
php laravel-schema-checker/check.php --generate-migrations
# Create database backup and run migrations
php laravel-schema-checker/check.php --generate-migrations --backup-db --run-migrations
# Environment-aware execution (auto-detects DDEV/Docker/local)
./laravel-schema-checker/run-checker.sh --generate-migrations --backup-db --run-migrations| Option | Description |
|---|---|
--fix |
Fix model $fillable properties automatically |
--dry-run |
Show what would be changed without applying |
--generate-migrations |
Generate Laravel migrations |
--run-migrations |
Run migrations after generating them |
--backup-db |
Create database backup before running migrations |
--backup |
Show database backup recommendations |
--json |
Output results in JSON format |
--help, -h |
Show help message |
The tool automatically detects and adapts to different environments:
- DDEV Projects: Uses
ddev exec phpcommands - Docker Containers: Runs commands directly in containers
- Local PHP: Uses local PHP installation
# Step 1: Check for issues
php laravel-schema-checker/check.php
# Step 2: Generate migrations for missing tables
php laravel-schema-checker/check.php --generate-migrations
# Step 3: Create backup and run migrations automatically
php laravel-schema-checker/check.php --run-migrations --backup-db
# Or do it all in one command
php laravel-schema-checker/check.php --generate-migrations --run-migrations --backup-db# JSON output for automated processing
php laravel-schema-checker/check.php --json > schema_check.json
# Dry run to check for issues without making changes
php laravel-schema-checker/check.php --dry-run# In DDEV projects
ddev exec php laravel-schema-checker/check.php --fix
# Using the auto-detecting wrapper
./laravel-schema-checker/run-checker.sh --generate-migrations --backup-db --run-migrationsThe tool uses sensible defaults but can be configured by modifying the src/config/CheckConfig.php file:
- Models Directory: Path to your Laravel models
- Migrations Directory: Where to generate migrations
- Excluded Fields: Fields to ignore in comparisons (id, created_at, updated_at)
- Log File Location: Where to write execution logs
- Database Backup: Automatic backup creation before migrations
- Dry Run Mode: Preview changes without applying them
- Error Handling: Comprehensive error reporting and rollback suggestions
- Environment Detection: Prevents incorrect command execution
The tool generates:
- Console Output: Real-time progress and results
- Log Files: Detailed execution logs with timestamps
- Migration Files: Laravel migration files for schema changes
- Database Backups: SQL dump files before migrations
-
"Could not find Laravel project root"
- Ensure you're running the tool from within a Laravel project directory
- The tool looks for the
artisanfile to detect Laravel projects
-
Database Connection Issues
- Check your Laravel database configuration
- Ensure database credentials are correct
-
Permission Issues
- Make sure the tool can write to the migrations directory
- Check file permissions for log files and backups
php laravel-schema-checker/check.php --help- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Converted to standalone tool that can be copied to any Laravel project
- Added environment-aware command execution
- Implemented automatic database backup functionality
- Enhanced migration generation with relationship support
- Added JSON output support for CI/CD integration
- Fixed excluded fields issue in model comparisons
- Improved field filtering logic
- Initial release with basic model-database comparison
- Support for fillable property fixes
- Migration and SQL file generation