<?php
class Product extends Eloquent {
protected appends = array('category');
public function category()
{
return $this->belongsTo('Models\Category',
'category_id');
}
}
如何做到这一点?
最佳答案
<?php
class Product extends Eloquent {
protected $with = array('category');
//protected $appends = array('category');
public function category()
{
return $this->belongsTo('Models\Category',
'category_id');
}
}
定义一个
$with
属性而不是 $appends
属性(property)。这是一个急切的负载。
关于Laravel Eloquent,附加与关系同名的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21851407/