Skip to content

Controlling the database schema in Laravel

When you're developing an application in Laravel, you'll often need to make changes to your database schema as you add new features or modify existing ones. Laravel provides a powerful tool called migrations that allows you to manage changes to your database schema in a version-controlled manner.

When you run the php artisan migrate command, Laravel will perform any new migrations that haven't been run on your database yet. This allows you to keep your database schema in sync with your code as you make changes.

However, sometimes you may need to roll back your migrations and start fresh. This is where the php artisan migrate:refresh command comes in. This command will undo all of your migrations and then re-run them from the beginning.

But what if you also want to seed your database with some default data after running your migrations? That's where the --seed option comes in. When you run the php artisan migrate:refresh --seed command, Laravel will first undo all of your migrations and then re-run them from scratch. After that, it will run all of your seeders to populate your database with any initial data you've defined.