Bird
0
0

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

easy📝 Syntax Q3 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->text('title');
C$table->char('title');
D$table->string('title');
Step-by-Step Solution
Solution:
  1. Step 1: Recall Laravel migration column types

    Laravel uses string for VARCHAR columns, so $table->string('title'); is correct.
  2. Step 2: Understand other options

    text is for longer text, varchar is not a Laravel method, char is fixed length and less common.
  3. Final Answer:

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

    String column = $table->string() [OK]
Quick Trick: Use $table->string() for VARCHAR columns [OK]
Common Mistakes:
  • Using varchar() which is invalid in Laravel
  • 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