0
0
Laravelframework~20 mins

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

Choose your learning style9 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.