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

danichurras's avatar

Route grouping with controller

I've been carrying out a project since Laravel 7.

I tried to use the (relatively)new controller group described in https://laravel.com/docs/9.x/routing#route-group-controllers but with no success. My Route facade doesn't have the controller static method documentated in the docblock and after tinkering a bit, I found out that my RouteRegistrar does not allow the controller attribute as well.

I wrote a dummy test like this:

Route::controller(TestController::class)->group(function () {
		Route::get('/test', 'test');
});

and I get the 'Attribute [controller] does not exist' exception in RouteRegistrarFile.php.

I've tried to composer update and composer install after deleting vendor. Maybe it's some residual config file from older laravel versions?

Here are my dependencies versions in composer.json:

    "require": {
        "php": "^8.1.5",
        "askedio/laravel-soft-cascade": "^7.0.0|9.*",
        "barryvdh/laravel-dompdf": "^1.0",
        "doctrine/dbal": "v2.*",
        "fakerphp/faker": "^1.16",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.0|^7.0.1",
        "kevinrob/guzzle-cache-middleware": "^3.5",
        "laravel/framework": "^9.0",
        "laravel/tinker": "^2.0",
        "laravelcollective/html": "^6.0",
        "uepg/sgi-authorizer": "0.2.*",
        "uepg/sgi-user": "1.1.*",
        "venturecraft/revisionable": "^1.32"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.8",
        "spatie/laravel-ignition": "^1.0",
        "laravel/dusk": "^6.21",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.0",
        "squizlabs/php_codesniffer": "^3.4"
    },

Thanks in advance 😁.

0 likes
4 replies
Tray2's avatar

Have you imported the controller class in your web.php file?

use App\Http\Controllers\TestController;
thinkverse's avatar

The controller method should be in Laravel 9, it was added back in Laravel 8.80 so. Check your Laravel version to make sure you're running Laravel 9.

Illuminate\Foundation\Application::VERSION

Please or to participate in this conversation.