Bird
0
0

What is wrong with this Laravel route definition?

medium📝 Debug Q7 of 15
Laravel - Basics and Architecture
What is wrong with this Laravel route definition?
Route::get('user/profile', 'UserController@profile');
AController should be passed as an array with class and method
BRoute URL missing leading slash
CHTTP method should be post, not get
DUserController does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Recall Laravel 8+ route syntax

    Laravel 8+ requires controller routes to use array syntax: [ControllerClass::class, 'method'].
  2. Step 2: Identify syntax error

    Passing controller as string 'UserController@profile' is deprecated and causes errors.
  3. Final Answer:

    Controller should be passed as an array with class and method -> Option A
  4. Quick Check:

    Use array syntax for controllers in routes [OK]
Quick Trick: Use [Controller::class, 'method'] for routes [OK]
Common Mistakes:
  • Using string syntax for controller
  • Thinking URL needs leading slash
  • Wrong HTTP method assumption

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes