Laravel 5.5 - Class Custom BaseController not found but exists

守給你的承諾、 提交于 2019-12-13 02:57:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!