20
SepMigrations are like version control for your database. They enable you to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application’s schema. The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel’s supported database systems. Typically, migrations will use this facade to create and modify database tables and columns.
You can utilize the make:migration
Artisan command to generate a database migration. After running this command the new migration will be placed in your database/migrations
directory. If we talk about the file name of each migration file, it has been seen that each migration file name includes a timestamp that enables Laravel to manage the order of the migrations:
php artisan make:migration create_products_table
Laravel will utilize the name of the migration to try to guess the name of the table and whether or not the migration will be creating a new table.
A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.
For example, the following migration creates a products table:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
To run all of your outstanding migrations, you have to run this migrate Artisan command:
php artisan migrate
To roll back the latest migration operation, you can utilize the rollback Artisan command.
Rollback The Last Migration Operation
php artisan migrate:rollback
Rollback all migrations
php artisan migrate:reset
Rollback all migrations and run them all again
php artisan migrate:refresh
php artisan migrate:refresh --seed
Codebrisk is mainly considered to be one of the best companies that are involved in rendering services related to the Laravel migration services. You can also think about hiring Laravel migration solutions and service providers from Codebrisk as they are mainly involved in offering various migration solutions and services. Because our expert developers have many years of experience in providing such relevant services. Therefore it helps to meet the specific requirements of the clients. So If you want to talk with us, you can contact us or Start a project with us.
Published at : 20-09-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project