Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

manimonji's avatar

Why Route::group is not mentioned in laravel docs? Is it deprecated?

Laravel 12 docs doesn't mention anything about a method that can allow you to group multiple properties in one go, is it old, unsafe or something like that? should I use two or many nested groups instead?

Route::group(['prefix' => '/comics/{comic:slug}/episodes', 'name' => 'episodes.'], function () {
    Route::get('/create', [EpisodeController::class, 'create'])->middleware(['role:admin'])->name('create');
    Route::post('/', [EpisodeController::class, 'store'])->middleware(['role:admin'])->name('store');
    Route::get('/{episode:number}', [EpisodeController::class, 'show'])->name('show');
    
    Route::group(['middleware' => ['role:admin']], function () {
        Route::get('/{episode:number}/edit', [EpisodeController::class, 'edit'])->name('edit');
        Route::put('/{episode:number}', [EpisodeController::class, 'update'])->name('update');
        Route::delete('/{episode:number}', [EpisodeController::class, 'destroy'])->name('destroy');
    });
});

1 like
4 replies
manimonji's avatar

Now that I think a bit more, I guess chaining the functions introduced in the laravel docs might be the newer way to do it:

Route::prefix('/comics/{comic:slug}/episodes')->name('episodes.')->group(function () {
    Route::get('/create', [EpisodeController::class, 'create'])->middleware(['role:admin'])->name('create');
    Route::post('/', [EpisodeController::class, 'store'])->middleware(['role:admin'])->name('store');
    Route::get('/{episode:number}', [EpisodeController::class, 'show'])->name('show');
    
    Route::group(['middleware' => ['role:admin']], function () {
        Route::get('/{episode:number}/edit', [EpisodeController::class, 'edit'])->name('edit');
        Route::put('/{episode:number}', [EpisodeController::class, 'update'])->name('update');
        Route::delete('/{episode:number}', [EpisodeController::class, 'destroy'])->name('destroy');
    });
});
manimonji's avatar

@martinbean Route groups, yes. But Route::group method is not mentioned, I just asked in case it's deprecated. Got the code from AI. And I didn't knew that you can chaing the route group functions

martinbean's avatar

Route groups, yes. But Route::group method is not mentioned, I just asked in case it's deprecated. Got the code from AI. And I didn't knew that you can chaing the route group functions

@manimonji What do you mean it’s not mentioned? The Route::group method is shown in examples of route groups because—as the name suggests—that’s exactly what that method is!

Got the code from AI. And I didn't knew that you can chaing the route group functions

Maybe use that as an indication that you should be reading the official docs, which are written and reviewed by humans for accuracy; and not relying on A.I. which is known to be wrong or confidently spout incorrect nonsense.

Please or to participate in this conversation.