2017-07-13 63 views
1

在我的Laravel 5.4模型之一,我有多个访问器。就像这样:Laravel通过accessor vue

public function getRevenueAttribute() 
{ 
    return $this->calculate()->revenue($this->price, $this->amount); 
} 

的问题是,当我的模型传递给我的VUE组件:

<product :prp-product="{{json_encode($product)}}"></product> 

product.revenue不存在。有没有办法做到这一点?我不想再次用vue来计算这些东西。

非常感谢。

回答

2

您需要为您的模型添加appends属性才能获得更多信息,请参阅this

/** 
* The accessors to append to the model's array form. 
* 
* @var array 
*/ 
protected $appends = ['revenue'];