Bird
0
0

You have this route registration:

medium📝 Debug Q14 of 15
Laravel - Controllers
You have this route registration:
Route::apiResource('products', ProductController::class);

But when you try to access GET /products/create, you get a 404 error. Why?
ABecause the ProductController is missing the create method
BBecause apiResource does not create routes for create and edit methods
CBecause the route URL is incorrect and should be /product/create
DBecause GET requests are not allowed on apiResource routes
Step-by-Step Solution
Solution:
  1. Step 1: Understand apiResource route behavior

    The apiResource method registers only API routes and excludes routes for creating and editing resources, such as /create and /edit, which are typically used for web forms.
  2. Step 2: Analyze the 404 error cause

    Since /products/create route is not registered by apiResource, accessing it results in a 404 error. This is expected behavior.
  3. Final Answer:

    Because apiResource does not create routes for create and edit methods -> Option B
  4. Quick Check:

    apiResource excludes create/edit routes [OK]
Quick Trick: apiResource skips create/edit routes, use resource for them [OK]
Common Mistakes:
  • Expecting create route with apiResource
  • Thinking route URL is wrong
  • Assuming GET requests are blocked

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes