0
0
Laravelframework~30 mins

Schema builder (columns, types) in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Laravel Schema Builder: Create a Users Table
📖 Scenario: You are building a simple user management system. You need to create a database table to store user information like name, email, and age.
🎯 Goal: Create a Laravel migration using the Schema builder to define a users table with specific columns and types.
📋 What You'll Learn
Create a migration file with a users table
Add columns with correct data types using Laravel Schema builder
Use the up method to define the table structure
Include a primary key column id with auto-increment
💡 Why This Matters
🌍 Real World
Creating database tables with migrations is a common task in Laravel projects to manage data structure safely and consistently.
💼 Career
Understanding Laravel's Schema builder is essential for backend developers working with Laravel to build and maintain databases.
Progress0 / 4 steps
1
Create the users table with an id column
Write the up method inside the migration class. Use Schema::create to create a table named users. Inside the callback, add an id column using $table->id().
Laravel
Need a hint?

Use Schema::create('users', function (Blueprint $table) { ... }) and inside add $table->id();

2
Add name and email columns
Inside the Schema::create callback, add a name column of type string and an email column of type string using $table->string('name') and $table->string('email').
Laravel
Need a hint?

Use $table->string('name'); and $table->string('email'); inside the callback.

3
Add an age column with integer type
Add an age column of type integer using $table->integer('age') inside the Schema::create callback.
Laravel
Need a hint?

Use $table->integer('age'); inside the callback.

4
Add timestamps columns
Add Laravel's automatic timestamp columns created_at and updated_at by calling $table->timestamps() inside the Schema::create callback.
Laravel
Need a hint?

Use $table->timestamps(); to add created_at and updated_at columns.