0
0
Laravelframework~5 mins

Schema builder (columns, types) in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of Laravel's Schema Builder?
Laravel's Schema Builder helps you create and modify database tables using PHP code instead of writing raw SQL. It makes managing database structure easier and more readable.
Click to reveal answer
beginner
How do you add a string column named 'title' to a table using Laravel's Schema Builder?
Use the method $table->string('title'); inside the Schema::create or Schema::table callback to add a string column called 'title'.
Click to reveal answer
beginner
Name three common column types you can define with Laravel's Schema Builder.
Common column types include:
  • string for short text
  • integer for whole numbers
  • boolean for true/false values
Click to reveal answer
intermediate
What method would you use to add a nullable column in Laravel's Schema Builder?
You chain the nullable() method to the column definition, like $table->string('description')->nullable(); to allow the column to hold NULL values.
Click to reveal answer
beginner
How do you create an auto-incrementing primary key column in Laravel's Schema Builder?
Use $table->id(); which creates an unsigned big integer column named 'id' that auto-increments and is the primary key.
Click to reveal answer
Which method adds a date and time column in Laravel's Schema Builder?
A$table->boolean('created_at');
B$table->string('created_at');
C$table->integer('created_at');
D$table->dateTime('created_at');
How do you make a column optional (can be NULL) in Laravel's Schema Builder?
AAdd <code>->optional()</code> after the column type
BAdd <code>->nullable()</code> after the column type
CAdd <code>->default(NULL)</code> after the column type
DAdd <code>->null()</code> after the column type
What does $table->timestamps(); do in a migration?
AAdds 'created_at' and 'updated_at' timestamp columns
BAdds a single timestamp column named 'timestamps'
CAdds a boolean column named 'timestamps'
DAdds an integer column named 'timestamps'
Which column type is best for storing true/false values?
Aboolean
Btext
Cinteger
Dstring
How do you drop a column named 'age' using Schema Builder?
A$table->deleteColumn('age');
B$table->remove('age');
C$table->dropColumn('age');
D$table->drop('age');
Explain how to add different column types using Laravel's Schema Builder and give examples.
Think about methods like string(), integer(), boolean(), nullable(), and id().
You got /5 concepts.
    Describe how Laravel's Schema Builder helps manage database tables compared to writing raw SQL.
    Focus on benefits of using Schema Builder for beginners and teams.
    You got /5 concepts.