How do you run migrations in Laravel (8, 9, 10, 11)?

Support Laravel Version: Laravel 8, Laravel 9, Laravel 10, Laravel 11 With Latest All Version Support.

In Laravel running migrations is a straightforward process using the Artisan command-line interface. Here’s how you can run migrations in Laravel:

1. Open your terminal or command prompt.

2. Navigate to your Laravel project directory if you’re not already there.

3. Run the following Artisan command to run all pending migrations:

php artisan migrate

This command will execute all migration files that haven’t been run yet. Laravel will track which migrations have already been executed in the database, so only pending migrations will be executed.

If you want to refresh the entire database by rolling back all migrations and re-running them, you can use the `migrate:refresh` command:

php artisan migrate:refresh

Be cautious when using `migrate:refresh` as it will wipe out all data in your database tables and re-run all migrations, including the `down` method of each migration.

You can also rollback the last batch of migrations using the `migrate:rollback` command:

php artisan migrate:rollback

This command will undo the last batch of migrations that were run, effectively rolling back the changes made by those migrations.

Remember to review your migrations and database changes carefully before running migration commands, especially in production environments, to avoid accidental data loss or schema changes.