Intermediate
How do you create a migration in Laravel?
Migrations in Laravel are like version control for your database, allowing you to define and modify database tables easily.
To create a migration, follow these steps:
- Open your terminal.
- Run the command:
php artisan make:migration create_users_table
. - Define the schema in the generated migration file located in
database/migrations
.
For instance, to create a users table, you would write:
Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->timestamps(); });