Bird
0
0

Which of the following is the correct syntax to add a string column named title in a Laravel migration?

easy📝 Syntax Q12 of 15
Laravel - Database Basics and Migrations
Which of the following is the correct syntax to add a string column named title in a Laravel migration?
A$table->varchar('title');
B$table->string('title');
C$table->text('title');
D$table->char('title');
Step-by-Step Solution
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]
Quick Trick: Use $table->string() for VARCHAR columns [OK]
Common Mistakes:
  • Using varchar() which does not exist
  • Confusing text() with string()
  • Using char() without length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes