Skip to content
Advertisement

Laravel 5.5 pass variable to child controller return always null?

I have a main controller CmsController, which is extended to default Laravel controller:

use AppHttpControllersController;
class CmsController extends Controller
{
    protected $web = null;

    public function __construct(Request $request)
    {
        $this->web = Web::domain($request->domain)->first();
    }
}

Now, in this controller I want to call $this->web

use AppHttpControllersWebPageController;
class PageController extends CmsController
{
    public function getPage(Request $request)
    {
        dd($this->web); // returns always null
    }
}

The data that should be returned is 100% correct, request parameters are also there.

Can someone give me a idea, what I did wrong here?

Advertisement

Answer

I think you need to execute parent constructor:

class PageController extends CmsController
{
    public function __construct()
    {
         parent::__construct();
         ....
    }
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement