属性 [规范] 在此 collection 实例上不存在
Property [specifications] does not exist on this collection instance
已解决:回答如下。
我将 Laravel 项目从 5.3 升级到 5.4,然后升级到 5.5。
目前唯一有问题的是当我进入产品编辑页面时出现错误:
Property [specifications] does not exist on this collection instance.
异常:
public function __get($key)
{
if (! in_array($key, static::$proxies)) {
throw new Exception("Property [{$key}] does not exist on this collection instance.");
}
return new HigherOrderCollectionProxy($this, $key);
}
这是由 blade 模板中的这一行引起的:
@if($categories->specifications->first())
$categories
变量像这样从 ProductController 传递给视图:
$categories = Category::with('specifications.attributes')->find($product->getCategoryId());
5.4/5.5 中有什么变化可能会破坏这行代码?
出于某种原因,我必须在访问规范之前将 ->first()
添加到 $categories
。
$categories->first()->specifications->first()
在同一视图中,此 $product->categories->first()
工作正常,返回方式与控制器中的类别相同,但不需要另一个 ->first()
。不知道为什么。
已解决:回答如下。
我将 Laravel 项目从 5.3 升级到 5.4,然后升级到 5.5。
目前唯一有问题的是当我进入产品编辑页面时出现错误:
Property [specifications] does not exist on this collection instance.
异常:
public function __get($key)
{
if (! in_array($key, static::$proxies)) {
throw new Exception("Property [{$key}] does not exist on this collection instance.");
}
return new HigherOrderCollectionProxy($this, $key);
}
这是由 blade 模板中的这一行引起的:
@if($categories->specifications->first())
$categories
变量像这样从 ProductController 传递给视图:
$categories = Category::with('specifications.attributes')->find($product->getCategoryId());
5.4/5.5 中有什么变化可能会破坏这行代码?
出于某种原因,我必须在访问规范之前将 ->first()
添加到 $categories
。
$categories->first()->specifications->first()
在同一视图中,此 $product->categories->first()
工作正常,返回方式与控制器中的类别相同,但不需要另一个 ->first()
。不知道为什么。