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');
}| Command | Purpose |
|---|---|
| php artisan migrate | Runs pending migrations |
| php artisan migrate:rollback | Reverts 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?