Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 5 of 10 · Laravel Framework Fundamentals
Interview question

What are Laravel migrations and why are they useful? Laravel migrations क्या हैं और क्यों उपयोगी हैं?

Answer

Migrations are version control for your database schema, written as PHP code instead of manual SQL, so schema changes can be tracked, shared, and rolled back.

php artisan make:migration create_posts_table

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}

public function down()
{
    Schema::dropIfExists('posts');
}
CommandPurpose
php artisan migrateRuns pending migrations
php artisan migrate:rollbackReverts the last batch

Migrations database schema के लिए version control हैं, PHP code में लिखे जाते हैं ताकि schema changes track और share हो सकें।

php artisan make:migration create_posts_table

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}

public function down()
{
    Schema::dropIfExists('posts');
}

Was this answer clear?