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

sajidsajad's avatar

using multiple controllers in any php file

I have a question regarding using multiple controllers at the beginning of any php file. e.g. in routes/web.php file, sometimes we have to use controllers like this:

use App\Http\Controllers\Controller1;

use App\Http\Controllers\Controller2;

use App\Http\Controllers\Controller3;

use App\Http\Controllers\Controller4;

my question is "is there any concise or short syntax" to write such lines in one go as there is a repetition of 'use App\Http\Controllers' in every single line?

Thanks

0 likes
5 replies
tykus's avatar
tykus
Best Answer
Level 104

You can use the following syntax:

use App\Http\Controllers\{Controller1,Controller2,Controller3,Controller4}
1 like
martinbean's avatar

@sajidsajad You can import namespaces, and then use relative class paths:

use App\Http\Controllers;

// Following will resolve to App\Http\Controllers\FooController
Route::get('/foo', [Controllers\FooController::class]);

// Following will resolve to App\Http\Controllers\BarController
Route::get('/bar', [Controllers\BarController::class]);
1 like
sajidsajad's avatar

@martinbean thanks for the answer but i think here we need to prefix 'Controllers' with every controller name.

Please or to participate in this conversation.