Bird
0
0

What is wrong with this route code in routes/web.php?

medium📝 Debug Q14 of 15
Laravel - Basics and Architecture
What is wrong with this route code in routes/web.php?
Route::get('/', function {
    return 'Welcome!';
});
AMissing semicolon after return statement
BMissing parentheses after function keyword
CRoute method should be post, not get
DThe string should be in double quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check the function syntax

    Anonymous functions in PHP require parentheses even if no parameters are passed.
  2. Step 2: Identify the syntax error

    The code misses parentheses after function, causing a syntax error.
  3. Final Answer:

    Missing parentheses after function keyword -> Option B
  4. Quick Check:

    Anonymous function needs () [OK]
Quick Trick: Always add () after function for anonymous functions [OK]
Common Mistakes:
  • Forgetting parentheses after function
  • Thinking semicolon is missing after return
  • Confusing HTTP methods get/post
  • Believing string quotes cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes