Migrations are files which contain a class definition with both an up()
and a down()
method. The up()
method is run when the migration is executed to apply changes to the database. The down()
method is run to revert the changes.
To use this, first, open the command prompt and then navigate to the root directory of laravel.
php artisan migrate:install
This command causes to create a special table in your database to keep track of what migrations have already been executed.
To create a new migration, run this command:
php artisan migrate:make CreateFlightsTable
This command will create a simple class file inside the migration folder.In this file you will see these two methods up() and down(). Both methods are blank.
if you want to add your custom schema then you can add a custom column inside the migration file.
The code should be like this.
public function up() { Schema::create('flights', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('airline'); $table->timestamps(); }); } public function down() { Schema::drop('flights'); }
Now when you want to migrate just run the command.
php artisan migrate application
Then you go to your database, you will see the flights table with that field.