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

richardhulbert's avatar

Route:controller bug?

Hi there Laracasters! Can someone explain why this works:

Route::prefix('admin/styles/')->middleware(['middleware'=>'auth'])->group(function(){
    Route::get('',[StylesController::class,'index'])->name('theme');
});

but this doesn't

use App\Http\Controllers\admin\StylesController;
Route::controller(StylesController::class)->prefix('admin/styles/')->middleware(['auth'])->group(function(){
    Route::get('','index')->name('theme');
});

I get Controller class does not exist? What I have missed?

I am using as reference this page:

https://laravel.com/docs/8.x/routing#route-group-controllers

0 likes
3 replies
Wilfried001's avatar

Essaie ça

Route::get(' ',[StylesController::class,'index'])->name('theme');

richardhulbert's avatar

@Wilfried001 Merci Wilfred mais vous n'avez pas compris ma question. Vous venez de me montrer l'exemple que j'ai déjà donné.

Si vous utilisez la méthode 'controller()' à 'Route' vous pouvez, selon la documentation, passer simplement la méthode controller - voir le lien

For the non Francophones (or those who don't want to use 'translate'):

Thank you Wilfred but you have not understood my question. You have just shown me the example I have already given.

If you use the method, 'controller()' to 'Route' you can, according to the documentation, simple pass the contoller method - see the link

Please or to participate in this conversation.