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
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;
}
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.