2017-07-13 61 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'];