【问题标题】:Laravel ErrorException when trying to access model attribute尝试访问模型属性时 Laravel ErrorException
【发布时间】:2016-10-12 17:51:56
【问题描述】:

我有 $formas_pagos 变量加载了 FormasPago 模型数据。当我通过 $formas_pagos 进行迭代时,如果我进行转储并死掉,我一切正常:

但是如果我想访问,例如,访问 'anio' 属性做 $forma_pago->anio;,我得到了这个 ErrorException

如果我这样做

$attributes = $forma_pago->getAttributes();
$attributes['anio'];

在foreach中,我可以得到'anio'属性。

【问题讨论】:

    标签: php laravel foreach model attributes


    【解决方案1】:

    问题是我的模型有复合键。我将其切换为具有自动增量 id pk,并解决了我的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 2018-03-07
      • 2012-03-18
      • 2019-03-09
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多