0
0
Laravelframework~30 mins

Migration creation in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Migration creation
📖 Scenario: You are building a simple Laravel application to manage a list of books in a library. You need to create a database table to store book information.
🎯 Goal: Create a Laravel migration file that defines a books table with specific columns.
📋 What You'll Learn
Create a migration file named create_books_table
Define a books table with columns: id, title, author, published_year, and timestamps
Set id as an auto-incrementing primary key
Make title and author columns strings
Make published_year an integer
💡 Why This Matters
🌍 Real World
Migrations help you create and modify database tables in a safe, version-controlled way when building Laravel applications.
💼 Career
Knowing how to write migrations is essential for backend Laravel developers to manage database schema changes collaboratively.
Progress0 / 4 steps
1
Create the migration class skeleton
Create a migration class named CreateBooksTable that extends Migration. Inside it, add empty up and down methods.
Laravel
Need a hint?

Start by defining the migration class and the two required methods up and down.

2
Add the table creation schema
Inside the up method, use Schema::create to create a table named books with a Blueprint callback parameter named $table.
Laravel
Need a hint?

Use Schema::create with the table name books and a callback function with $table as parameter.

3
Define the columns inside the table
Inside the Schema::create callback, add these columns to $table: an auto-incrementing id, string title, string author, integer published_year, and timestamps.
Laravel
Need a hint?

Use the Laravel schema builder methods to add the columns with the exact names and types.

4
Add the table drop in the down method
Inside the down method, add code to drop the books table using Schema::dropIfExists('books').
Laravel
Need a hint?

Use Schema::dropIfExists with the table name books to remove the table when rolling back.