Bird
0
0

You want to create a resource controller for Product but only want to generate routes for index, show, and store methods. Which is the correct way to register this in routes/web.php?

hard📝 Application Q15 of 15
Laravel - Controllers
You want to create a resource controller for Product but only want to generate routes for index, show, and store methods. Which is the correct way to register this in routes/web.php?
ARoute::resource('products', ProductController::class)->except(['create', 'edit']);
BRoute::resource('products', ProductController::class)->only(['index', 'show', 'store']);
CRoute::resource('products', ProductController::class)->skip(['create', 'edit']);
DRoute::resource('products', ProductController::class)->filter(['index', 'show', 'store']);
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to limit resource routes

    Laravel allows limiting routes using the only method with an array of method names.
  2. Step 2: Evaluate each option

    A uses except(['create', 'edit']) which excludes only create and edit, leaving index, store, show, update, and destroy. B correctly uses only(['index', 'show', 'store']). C and D use invalid methods skip and filter.
  3. Final Answer:

    Route::resource('products', ProductController::class)->only(['index', 'show', 'store']); -> Option B
  4. Quick Check:

    Limit resource routes with only([...]) [OK]
Quick Trick: Use ->only([...]) to limit resource controller routes [OK]
Common Mistakes:
  • Using invalid methods like skip or filter
  • Confusing only with except
  • Not passing array to only method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes