Laravel larvel relationship$当使用';访问时,返回null;与';功能

Laravel larvel relationship$当使用';访问时,返回null;与';功能,laravel,eloquent,Laravel,Eloquent,在急于加载关系时,它返回空数组作为结果,但在获得结果后,关系工作正常 包含函数$this的内部关系在加载时没有属性值 我已尝试在不立即加载的情况下立即加载关系,$this具有所有属性值 控制器 模型 $this应该有属性值。试试这个 $temp = StipendCalcVols::where('vol_id', 110)->first(); $temp = $temp->load('stipendCalcTypes'); 试试这个 $temp = StipendCalcV

在急于加载关系时,它返回空数组作为结果,但在获得结果后,关系工作正常

包含函数$this的内部关系在加载时没有属性值

我已尝试在不立即加载的情况下立即加载关系,
$this
具有所有属性值

  • 控制器
  • 模型
$this
应该有属性值。

试试这个

$temp = StipendCalcVols::where('vol_id', 110)->first();
$temp = $temp->load('stipendCalcTypes');
试试这个

$temp = StipendCalcVols::where('vol_id', 110)->first();
$temp = $temp->load('stipendCalcTypes');
试试这个:

而不是:

$this->stipend_calc_id
使用以下命令:

$this->attributes['stipend_calc_id']
试试这个:

而不是:

$this->stipend_calc_id
使用以下命令:

$this->attributes['stipend_calc_id']

在您看来,
$this
此时应该具有哪些属性值?
$this->stipend\u calc\u id
$this->id
期望建模任何属性@NamoshekWell,当查询生成器急切地加载关系时,这些属性尚未设置。这也是因为您希望同时加载多个模型,而不是单独加载每个模型。Laravel不支持复合键。使用此软件包:在您看来,
$this
此时应该具有哪些属性值?
$this->stipend\u calc\u id
$this->id
期望建模任何属性@NamoshekWell,当查询生成器急切地加载关系时,这些属性尚未设置。这也是因为您希望同时加载多个模型,而不是单独加载每个模型。Laravel不支持复合键。使用此软件包: