Bird
Raised Fist0
Laravelframework~20 mins

Schema builder (columns, types) in Laravel - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Schema Builder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this Laravel migration column definition?
Consider this Laravel migration snippet:
Schema::create('products', function (Blueprint $table) {
$table->string('name', 100);
$table->decimal('price', 8, 2);
$table->timestamps();
});

What will be the SQL column types generated for name and price?
Laravel
Schema::create('products', function (Blueprint $table) {
  $table->string('name', 100);
  $table->decimal('price', 8, 2);
  $table->timestamps();
});
Aname: VARCHAR(255), price: DOUBLE
Bname: TEXT, price: FLOAT
Cname: VARCHAR(100), price: DECIMAL(8,2)
Dname: CHAR(100), price: DECIMAL(10,2)
Attempts:
2 left
💡 Hint
Look at the parameters passed to string() and decimal() methods.
📝 Syntax
intermediate
1:30remaining
Which option correctly defines a nullable integer column in Laravel schema?
You want to add an integer column named age that can be empty (nullable). Which of these Laravel schema builder lines is correct?
A$table->integer('age')->nullable();
B$table->integer('age')->null();
C$table->integer('age', true);
D$table->nullable()->integer('age');
Attempts:
2 left
💡 Hint
Check the method chaining order and method names.
🔧 Debug
advanced
2:00remaining
Why does this Laravel migration code cause an error?
Examine this migration snippet:
Schema::table('users', function (Blueprint $table) {
$table->string('email')->unique()->nullable(false);
});

Why will this cause an error or unexpected behavior?
Laravel
Schema::table('users', function (Blueprint $table) {
  $table->string('email')->unique()->nullable(false);
});
Aunique() must come after nullable(), order matters
Bnullable(false) is invalid; nullable() only accepts no arguments or true
Cstring() requires a length parameter, missing here
DYou cannot add unique constraint in a table modification
Attempts:
2 left
💡 Hint
Check the nullable() method signature in Laravel schema builder.
❓ state_output
advanced
1:30remaining
What is the default value of a boolean column defined like this in Laravel?
Given this migration code:
Schema::create('settings', function (Blueprint $table) {
$table->boolean('active');
});

What will be the default value of the active column if no default is set explicitly?
Laravel
Schema::create('settings', function (Blueprint $table) {
  $table->boolean('active');
});
Atrue (1)
Bfalse (0)
CNULL
DNo default, insert will fail without value
Attempts:
2 left
💡 Hint
Think about how databases handle columns without defaults and NOT nullable.
🧠 Conceptual
expert
2:30remaining
Which Laravel schema builder column type should you use for storing large JSON data efficiently?
You want to store large JSON data in a database column using Laravel's schema builder. Which column type is best suited for this purpose?
A$table->jsonb('data');
B$table->text('data');
C$table->json('data');
D$table->longText('data');
Attempts:
2 left
💡 Hint
Consider database support for JSON types and efficiency.

Practice

(1/5)
1. What does the Schema::create method do in Laravel migrations?
easy
A. Creates a new database table with specified columns
B. Deletes an existing database table
C. Updates data inside a table
D. Runs raw SQL queries directly

Solution

  1. Step 1: Understand the purpose of Schema::create

    This method is used to define a new table structure in the database.
  2. Step 2: Recognize the role of columns inside the callback

    The callback function receives a Blueprint object to define columns for the new table.
  3. Final Answer:

    Creates a new database table with specified columns -> Option A
  4. Quick Check:

    Schema::create = create table [OK]
Hint: Schema::create always defines a new table [OK]
Common Mistakes:
  • Confusing create with drop or update
  • Thinking it modifies data instead of structure
  • Assuming it runs raw SQL
2. Which of the following is the correct syntax to add a string column named title in a Laravel migration?
easy
A. $table->varchar('title');
B. $table->string('title');
C. $table->text('title');
D. $table->char('title');

Solution

  1. Step 1: Identify the correct method for string columns

    Laravel uses string() to create VARCHAR columns.
  2. Step 2: Check the syntax for adding a column

    The syntax is $table->string('column_name'); which matches $table->string('title');.
  3. Final Answer:

    $table->string('title'); -> Option B
  4. Quick Check:

    String column = $table->string('name') [OK]
Hint: Use $table->string() for VARCHAR columns [OK]
Common Mistakes:
  • Using varchar() which does not exist
  • Confusing text() with string()
  • Using char() without length
3. What will be the resulting column type in the database for this migration code?
$table->integer('age')->unsigned();
medium
A. Unsigned integer column
B. Signed integer column
C. String column named 'age'
D. Boolean column

Solution

  1. Step 1: Understand the integer() method

    This creates an integer type column in the database.
  2. Step 2: Analyze the effect of unsigned()

    The unsigned() modifier makes the integer only accept positive values (no negatives).
  3. Final Answer:

    Unsigned integer column -> Option A
  4. Quick Check:

    integer()->unsigned() = unsigned int [OK]
Hint: unsigned() means no negative numbers allowed [OK]
Common Mistakes:
  • Ignoring unsigned modifier
  • Thinking integer() creates string
  • Confusing with boolean type
4. Identify the error in this migration code snippet:
Schema::create('users', function (Blueprint $table) {
$table->string('email')->nullable;
});
medium
A. String columns cannot be nullable
B. Wrong method name, should be allowNull()
C. Blueprint object is not imported
D. Missing parentheses after nullable method

Solution

  1. Step 1: Check the nullable method usage

    In Laravel, nullable is a method and must be called with parentheses ().
  2. Step 2: Identify the missing parentheses

    The code uses nullable without (), causing a syntax error.
  3. Final Answer:

    Missing parentheses after nullable method -> Option D
  4. Quick Check:

    nullable() requires parentheses [OK]
Hint: Always add () after nullable method [OK]
Common Mistakes:
  • Writing nullable without ()
  • Using allowNull() instead of nullable()
  • Assuming string can't be nullable
5. You want to create a table with a primary key id that auto-increments, a nullable description text column, and a price decimal column with 8 digits total and 2 decimal places. Which migration code is correct?
hard
A. Schema::create('products', function (Blueprint $table) { $table->bigIncrements('id'); $table->text('description'); $table->decimal('price', 8, 2); });
B. Schema::create('products', function (Blueprint $table) { $table->integer('id')->autoIncrement(); $table->string('description')->nullable; $table->decimal('price', 8); });
C. Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->text('description')->nullable(); $table->decimal('price', 8, 2); });
D. Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->text('description')->nullable; $table->decimal('price', 8, 2); });

Solution

  1. Step 1: Check primary key and auto-increment

    $table->increments('id') creates an auto-incrementing primary key integer column.
  2. Step 2: Verify nullable text column syntax

    $table->text('description')->nullable(); correctly makes the text column nullable with parentheses.
  3. Step 3: Confirm decimal column precision

    $table->decimal('price', 8, 2); defines a decimal with 8 digits total and 2 decimal places.
  4. Final Answer:

    Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->text('description')->nullable(); $table->decimal('price', 8, 2); }); -> Option C
  5. Quick Check:

    increments + nullable() + decimal(8,2) = correct [OK]
Hint: Use increments() for PK, nullable() with (), decimal needs precision [OK]
Common Mistakes:
  • Forgetting parentheses on nullable()
  • Using autoIncrement() instead of increments()
  • Missing decimal precision arguments
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard