Laravel 5.5 – Class Custom BaseController not found but exists

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 IlluminateFoundationBusDispatchesJobs;
use IlluminateRoutingController as CheckController;
use IlluminateFoundationValidationValidatesRequests;
use IlluminateFoundationAuthAccessAuthorizesRequests;

class Controller extends CheckController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


}

Custom BaseController (BaseController.php)

use AppHttpControllersController;

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I believe you haven’t included full namespaces.

Make sure in BaseController you have:

namespace AppHttpControllers;

and in HomeController make sure you are using:
use AppHttpControllersBaseController;

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x