In this video we are going to learn about Database: Migrations.
Migrations are like version control for your database, allowing your team, to easily modify and share the application's database schema.
Migrations are typically paired with Laravel's schema builder to easily build your application's database schema.
So, lets create a migration.
Before creating a migration go to the phpmyadmin and here you can see.
There is no any table inside the database.
Ok, lets create a migration for the posts table.
So go to the command prompt and here run the following command.

php artisan make:migration create_posts_table --create=posts

Here posts is table name.
Now Migration is created inside the migration folder.
So, Lets find this migration.
Go to the project and click on database folder then click on migrations.
You can see here create_post_table migration, migrations contain a class definition with up() and down() method.
The up() method is run when the migration is executed to apply changes to the database and the down() method is run to revert the changes.
If you need to update the database you just create a new migration.
Now Inside the up function.
This is id column which is autoincrement and their type is bigInt.
and this is timestamp which creates two column created_at and updated_at.
Now add some more columns.


Now save the file and lets migrate this migration.
Swtich to the command prompt and run the following command.

php artisan migrate

Alirght now migrations is migrated.
So lets check the database.
Go to the phpmyadmin.
Refresh the database and you can see tables are created.
These 4 tables are laravel default migration.
This migration table take care all the migration and this is post table.
See inside the posts table all the columns which was added inside the posts migration file.
And these created_at and updated_at columns are coming from the timestamp.
Now lets see the Rolling Back Migrations.
So, To rollback the latest migration operation we can use rollback command.
So just goto the command prompt and type here.

php artisn migrate:rollback

Now go to the phpmyadmin and refresh the database and you can see here.
only migration table is here and other tables are removed from here because of the rollback migration command.
Alright now lets see the refresh migrations.
The migrate:refresh command will roll back all of your migrations and then execute the migrate command.
This command effectively re-creates your entire database:.
So go to the command prompt and run the command.

php artisan migrate:refresh

Its executed, Now you can see here all tables are re created.
Lets do one thing insert some record into the posts table.
Open post table and.
Click on insert and insert one or two records.
So just type here.
Title, and body.
Once again title and body.
Now click on go.
Click on browse.
You can see here the inserted records Ok now execute the migrate:refresh command.
So goto the command prompt.
and type here.

php artisan migrate:refresh

Ok command executed.
Now go to the phpmyadmin.
You can see here all the tables are re-created and inside the posts there is no any record.
So in this way you can use migration in laravel 8.