Joel Joel Binks
Joel Joel Binks

Reputation: 1666

Laravel 5 - constantly repeating use statements

Is there a central place where I can put 'use' statements so I don't have to keep doing things like this with every single controller I create?

<?php namespace App/Http/Controllers

use Session;
use Auth;
use Input;
use Log;
use Carbon;
use Response;
use Illuminate\Routing\Controller;

class BlaBlaController extends Controller {}

Just seems to violate DRYness and seems inefficient.

Upvotes: 3

Views: 174

Answers (1)

jfadich
jfadich

Reputation: 6348

Short answer: No.

The 'use' statements are resolving the namespaces for that file, so you can't inherit them from other files. It doesn't violate DRY because there isn't actually any logic that is being repeated.

Now if you don't want to have to include those use statement in every controller then you can just resolve the facade out of the global scope whenever you use it. For example the following will work from any namespace, without needing a use statement.

\Input::all();

In my opinion it looks a little cleaner to just include the use statement, but either will work.

Upvotes: 1

Related Questions