You cannot use Illuminate \ Routing \ Controller as a controller because the name is already in use

I learned to use Laravel, watching Larcasts and using Docs, I came across a lesson that describes Eloquent, but I was stuck in an error:

at HandleExceptions->fatalExceptionFromError( array( 'type' => '64', 'message' => 'Cannot use Illuminate\Routing\Controller as Controller because the name is already in use' ) ) 

I am very confused and now copied the above examples for sure, but I still get the error. I am using Laravel 5, so I don’t know if there was any kind of undocumented change or if I am just doing something wrong. I did not find anything related to Google search queries that solve the problem, so I was hoping someone here could help. Here is the error code:

 <?php namespace App\Http\Controllers; use Illuminate\Routing\Controller; use App\VarName; class VarController extends Controller { public function Var() { $Variable = VarName::get(); dd($Variable); } } 

According to the documentation, this should work, and in the video I watched, it worked. What am I missing?

I tried to remove the Controller class, because it seems that this is causing the already used error, which broke everything, reinstalled and tried to just use the Controller, as it extends the eloquent model, but now its statement:

Exception on line Pluralizer.php 258: call_user_func() expects parameter 1 to be a valid callback, mb_strtolower function not found, or invalid function name

which is beyond my understanding of Laravel’s inner workings, I’m stuck and I don’t understand the problem, according to the documentation, I don’t see anything bad in my code, it seems like such a simple step. all I'm trying to do is retrieve information from a database, what happens?

Thanks in advance for your help!

+7
php laravel laravel-5
source share
1 answer

Operator use Illuminate\Routing\Controller; does not work, because the App\Http\Controllers class already exists in the App\Http\Controllers namespace.

To solve the problem, you can change the namespace shortcut in the usage statement:

 use Illuminate\Routing\Controller as BaseController; 

However, the solution for your specific problem is that you probably just want to completely remove the use Illuminate\Routing\Controller; statement use Illuminate\Routing\Controller; .

In Laravel 5, the App\Http\Controllers\Controller class already extends the Illuminate\Routing\Controller class. It is assumed that all new controllers must then extend the class App\Http\Controllers\Controller . For example, take a look at the default values ​​of App\Http\Controllers\HomeController or App\Http\Controllers\WelcomeController , as they extend the class App\Http\Controllers\Controller .

In general, your two options:

 // rename the class in the use statement namespace App\Http\Controllers; use Illuminate\Routing\Controller as BaseController; // note the name of the class being extended class VarController extends BaseController { // snip } 

or

 // extend the existing App\Http\Controllers\Controller class namespace App\Http\Controllers; class VarController extends Controller { // snip } 
+16
source share

All Articles