php-派生属性未从父构造函数初始化
作者:互联网
在我的通用控制器GeneralController中:
use App\Http\Controllers\Controller;
class GeneralController extends Controller
{
protected $onLine = null;
public function __construct(Request $request)
{
$this->onLine = OnLine::domain($request->domain)->first();
}
}
在我的另一个控制器中,扩展GeneralController:
use App\Http\Controllers\OnLine\ItemController;
class ItemController extends GeneralController
{
public function getItem(Request $request)
{
dd($this->onLine); // but returns null :(
}
}
我已经检查过OnLine :: domain($request-> domain)-> first();返回数据.
解决方法:
父级构造函数将为您提供帮助!
class ItemController extends GeneralController
{
public function __construct()
{
parent::__construct();
....
}
}
标签:derived-class,laravel,laravel-5,oop,php 来源: https://codeday.me/bug/20191110/2013546.html