I have been learning to use Laravel, watching Larcasts and using the Docs, I came across a lesson where Eloquent is being described but I’m stuck with the error:
at HandleExceptions->fatalExceptionFromError( array( 'type' => '64', 'message' => 'Cannot use IlluminateRoutingController as Controller because the name is already in use' ) )
I’m very confused and have now copied the examples provided exactly but I still get the error. I am using Laravel 5, so I don’t know if there has been some undocumented change or If I am simply doing something wrong. I haven’t found anything related in google searches that solve the issue so I was hoping someone here might be able to help. Here is the code that is producing the error:
<?php namespace AppHttpControllers; use IlluminateRoutingController; use AppVarName; class VarController extends Controller { public function Var() { $Variable = VarName::get(); dd($Variable); } }
According to the documentation, this should work, and in the video that I watched, it did work.. what am I missing?
I tried deleting the Controller class, since it seems to be whats causing the already in use error, which broke everything, reinstalled and tried to just use Controller since it extends the eloquent model but now its saying:
ErrorException in Pluralizer.php line 258: call_user_func()
expects parameter 1 to be a valid callback, function mb_strtolower
not found or invalid function name
which is beyond my understanding of the inner workings of Laravel, I’m stuck and I don’t understand the problem, according to documentation I don’t see anything wrong with my code, this seems like such a simple step. all I’m trying to do is retrieve info from a database, what is going on?
Thanks in advance for any help!
Advertisement
Answer
The use IlluminateRoutingController;
statement is failing because there is already a Controller
class in the AppHttpControllers
namespace.
To solve the immediate issue, you can change namespace shortcut on the use statement:
use IlluminateRoutingController as BaseController;
However, the solution for your specific issue is that you probably just want to remove the use IlluminateRoutingController;
statement altogether.
In Laravel 5, the AppHttpControllersController
class already extends the IlluminateRoutingController
class. The intention is that all new controllers should then extend the AppHttpControllersController
class. For example, take a look at the default AppHttpControllersHomeController
or AppHttpControllersWelcomeController
, as both extend the AppHttpControllersController
class.
In summary, your two options are:
// rename the class in the use statement namespace AppHttpControllers; use IlluminateRoutingController as BaseController; // note the name of the class being extended class VarController extends BaseController { // snip }
Or
// extend the existing AppHttpControllersController class namespace AppHttpControllers; class VarController extends Controller { // snip }