Bird
0
0

You want to create a route group with prefix api/v1 and middleware auth:sanctum. Which code correctly applies both?

hard📝 Application Q8 of 15
Laravel - Routing
You want to create a route group with prefix api/v1 and middleware auth:sanctum. Which code correctly applies both?
ARoute::group(['prefix' => 'api/v1'], ['middleware' => 'auth:sanctum'], function () { /* routes */ });
BRoute::group(['middleware' => ['auth', 'sanctum'], 'prefix' => 'api/v1'], function () { /* routes */ });
CRoute::group('prefix' => 'api/v1', 'middleware' => 'auth:sanctum', function () { /* routes */ });
DRoute::group(['prefix' => 'api/v1', 'middleware' => 'auth:sanctum'], function () { /* routes */ });
Step-by-Step Solution
Solution:
  1. Step 1: Combine prefix and middleware in one associative array

    Both options must be keys in the same array passed as first argument.
  2. Step 2: Check syntax correctness

    Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:sanctum'], function () { /* routes */ }); correctly uses one array with both keys; others have syntax errors or wrong structure.
  3. Final Answer:

    Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:sanctum'], function () { /* routes */ }); -> Option D
  4. Quick Check:

    Use one array with all options in route group [OK]
Quick Trick: Put all options in one array for route groups [OK]
Common Mistakes:
  • Passing multiple arrays instead of one
  • Using invalid array syntax
  • Splitting options into separate arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes