โ ๏ธ This is an experimental feature, keep that in mind when using it
The lift:migration command allows you to generate a migration file based on your models. By default, it uses the App\Models namespace, but you can change it using the --namespace option.
All the created migration files will be placed inside the database/migrations folder.
Examples:
The command below will generate a migration file for the App\Models\User model.
phpartisanlift:migrationUser
The command below will generate a migration file for the App\Models\Auth\User model.
phpartisanlift:migrationAuth\User
The command below will generate a migration file for the App\Custom\Models\User model.
When the table for your model is already created in the database, the lift:migration command will generate a migration file to update the table based on the differences between the model and the database table.
// User.phpfinalclassUserextendsModel{useLift,SoftDeletes;publicint $id;publicstring $name;publicstring $username;publicstring $email;publicstring $password;public?bool $active;}// Migration file generated<?phpuseIlluminate\Database\Migrations\Migration;useIlluminate\Database\Schema\Blueprint;useIlluminate\Support\Facades\Schema;returnnewclassextendsMigration{/** * Run the migrations. */publicfunctionup():void {Schema::table('users',function (Blueprint $table) { $table->string('username')->after('name'); $table->dropColumn('created_at'); $table->dropColumn('updated_at'); $table->dropColumn('test'); }); }/** * Reverse the migrations. */publicfunctiondown():void {// Nothing to do here }};