Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maxccarvalho's avatar

Laravel 5 BaseController

Since in Laravel 5 the BaseController is gone, how to do things like:

Share variables or use Jeffrey Way Javascript helper to declare javascript in all of the views?

Thanks!

0 likes
3 replies
JeffreyWay's avatar
Level 59

If you want a BaseController, then manually create one. It's just simple inheritance.

2 likes
cardei's avatar

Hello! I manually tried to create the BaseController, I named it FrontController but something seams to not work like in Laravel 4.

I have a public property (array) public $cdada; in a FrontController and I assign some data in the __construct method.

The FrontController extends Controller

Then I have a ChildController extending the FrontController and if I make a dd($this->cdata); I get a null.

Thanks!

bobbybouwmann's avatar

I believe you have to call the constructor function of your parent controller if I understand your situation correctly

class FrontController extends Controller {

    protected $cdata;

    public function __construct()
    {
        $this->cdata = 'Something';
    }   

}

class ChildController extends FrontController {

    public function __construct() 
    {
        parent::__construct();

        dd($this->cdata);
    }   

}
5 likes

Please or to participate in this conversation.