问题
Laravel 5.5 Custom BaseController not found even though it exists. Have checked the other questions on StackOverflow regarding the BaseController not found but they are referring to the default BaseController which isn't the same in mine case.
Here is my implementation
Controller.php
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as CheckController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends CheckController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
Custom BaseController (BaseController.php)
use App\Http\Controllers\Controller;
class BaseController extends Controller
{
/**
* Setup the layout used by the controller.
*
* @return void
*/
public $data = array();
public function __construct()
{
if (Sentinel::check()) {
// User is not logged in, or is not activated
$this->data['admin'] = Sentinel::getUser();
}
}
protected function setupLayout()
{
if (!is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
}
}
Extending a class named HomeCtontroller to Custom BaseController
class HomeController extends BaseController {
protected $layout = 'master';
public function main()
{
...
}
}
And then it gives the following error
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Class 'BaseController' not found
Would appreciate any sort of pointers.
回答1:
I believe you haven't included full namespaces.
Make sure in BaseController you have:
namespace App\Http\Controllers;
and in HomeController make sure you are using:
use App\Http\Controllers\BaseController;
all those controllers should be located in app/Http/Controllers directory.
If you are sure you have valid directories and namespaces run composer dump-autoload in console
来源:https://stackoverflow.com/questions/47380843/laravel-5-5-class-custom-basecontroller-not-found-but-exists