Rbijker.com
Rbijker.com

Reputation: 3114

php artisan creates controller with "use App\Http\Controllers\Controller" but it is never used

When I create a controller in Laravel with the php artisan command

php artisan make:controller TestController

it create a controller which includes

use App\Http\Controllers\Controller 

PhpStorm hints: Alias "App\Http\Controllers\Controller" is never used.

This seems to be correct because the part

class TestController extends Controller

works fine without it. So can I remove the "use App\Http\Controllers\Controller" or am I missing something?

Upvotes: 1

Views: 297

Answers (1)

Jeff Lambert
Jeff Lambert

Reputation: 24661

You can safely remove that use statement. Inside of any given namespace you can safely reference any other class that is also inside of that namespace without having to provide a fully qualified name to it. Since both TestController and Controller are in the App\Http\Controllers namespace, then you should have no issue if you wish to remove that line.

If you move TestController or Controller to a different namespace, then you will need to import the Controller class inside of your TestController.

Upvotes: 1

Related Questions