route('profile.show', ['id' => 5])?Route::get('/user/{id}', function ($id) { return "User $id profile"; })->name('profile.show');
The route is defined with URL pattern /user/{id}. Using route('profile.show', ['id' => 5]) replaces {id} with 5, so the generated URL is /user/5.
The correct method to name a route is ->name('route.name') chained after the route definition. Option B uses this correctly.
route('admin.users.index')?Route::name('admin.')->group(function () { Route::get('/users', function () { return 'Users list'; })->name('users.index'); });
The name prefix admin. adds to the route's name, making it admin.users.index. The URL remains /users because no URL prefix is set.
route('product.show') cause an error?Route::get('/product/{id}', function ($id) { return "Product $id"; })->name('product.show');
The route URL requires an 'id' parameter. Calling route('product.show') without passing 'id' causes an error because Laravel cannot generate the URL.
Route::name('api.')->group(function () { Route::name('v1.')->group(function () { Route::get('/items', function () { return 'Items list'; })->name('items.index'); }); });
Laravel concatenates name prefixes from outer to inner groups. So api. + v1. + items.index becomes api.v1.items.index.
