Which of the following is the correct syntax to create a route group with a prefix api in Laravel?
easy📝 Syntax Q3 of 15
Laravel - Routing
Which of the following is the correct syntax to create a route group with a prefix api in Laravel?
ARoute::group(['prefix' => api], function () { /* routes */ });
BRoute::group('prefix' => 'api', function () { /* routes */ });
CRoute::group(['prefix' => 'api'], function () { /* routes */ });
DRoute::group(prefix: 'api', function () { /* routes */ });
Step-by-Step Solution
Solution:
Step 1: Review correct array syntax for options
Laravel expects an associative array with keys as strings and values as strings inside square brackets.
Step 2: Check each option for syntax errors
Route::group(['prefix' => 'api'], function () { /* routes */ }); uses correct array syntax with quotes around 'prefix' and 'api'. Others miss quotes or use invalid syntax.
Final Answer:
Route::group(['prefix' => 'api'], function () { /* routes */ }); -> Option C
Quick Check:
Correct array syntax with prefix key = Route::group(['prefix' => 'api'], function () { /* routes */ }); [OK]
Quick Trick:Use ['prefix' => 'value'] array syntax for route groups [OK]
Common Mistakes:
Omitting quotes around keys or values
Using parentheses instead of brackets for array
Using colon syntax not supported in PHP arrays
Master "Routing" in Laravel
9 interactive learning modes - each teaches the same concept differently