arrow_back
Back

Laravel migrations: schema builder, rollback, and Artisan

Andrew Dorokhov Andrew Dorokhov schedule 1 min read

Migrations are located in database/migrations/*.php. Example:

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        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();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};

Apply migrations:

php artisan migrate

Create a migration:

php artisan make:migration create_users_table

Rollback the last applied migrations:

php artisan migrate:rollback
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Laravel raw SQL: DB facade, select, and parameter binding

arrow_forward