adly-nady/php-my-migration
Laravel package to generate migrations (and optional Eloquent models) from an existing MySQL database. Detects column types, keys, indexes, foreign keys, timestamps/soft deletes; supports batch processing, custom paths, overwrite, and connections.
A powerful Laravel package that automatically generates migration files and Eloquent models from your existing database tables. Perfect for legacy projects or when you need to version control your database structure.
Installation • Usage • Examples • Features
✨ Smart Migration Generation
🎯 Eloquent Model Generation
🚀 Performance & Flexibility
Install the package via Composer:
composer require adly-nady/php-my-migration
The package will automatically register its service provider.
Generate migration files for all tables:
php artisan phpmymigration:generate
Generate both migrations and Eloquent models:
php artisan phpmymigration:generate --with-models
Generate only migration files (default behavior):
php artisan phpmymigration:generate --only-migrations
Use a specific database connection:
php artisan phpmymigration:generate --connection=mysql
Overwrite existing migration/model files:
php artisan phpmymigration:generate --force
Specify custom paths for migrations and models:
php artisan phpmymigration:generate --path=/custom/path
This will create:
/custom/path/migrations/ for migration files/custom/path/Models/ for model filesFor a users table with relationships:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::dropIfExists('users');
}
};
For the same users table:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* User Model
*
* @property int $id
* @property string $name
* @property string $email
* @property \DateTime|null $email_verified_at
* @property string $password
* @property string|null $remember_token
* @property \DateTime $created_at
* @property \DateTime $updated_at
* @property \DateTime|null $deleted_at
*/
class User extends Model
{
use SoftDeletes;
protected $fillable = [
'name',
'email',
'password',
];
protected $casts = [
'email_verified_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
}
Hi! I'm Adly Nady, a passionate Laravel developer. I love creating tools that make developers' lives easier. This package is one of my contributions to the Laravel ecosystem.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE.md file for details.
How can I help you explore Laravel packages today?