Bird
0
0

What is wrong with this Laravel route code?

medium📝 Debug Q14 of 15
Laravel - Basics and Architecture
What is wrong with this Laravel route code?
Route::get('/user', function {
    return 'User page';
});
AReturn statement is invalid.
BRoute::get should be Route::post.
CMissing parentheses after function keyword.
DRoute path must be '/users' not '/user'.
Step-by-Step Solution
Solution:
  1. Step 1: Check function syntax in route closure

    In PHP, anonymous functions require parentheses after the function keyword, even if empty.
  2. Step 2: Identify the error in the code

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

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

    Anonymous functions need () after function [OK]
Quick Trick: Anonymous functions always need () after function [OK]
Common Mistakes:
  • Ignoring missing parentheses syntax error
  • Thinking route method is wrong
  • Assuming return statement is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes