Reputation: 925
<?php
class Product extends Eloquent {
protected appends = array('category');
public function category()
{
return $this->belongsTo('Models\Category',
'category_id');
}
}
How to achieve that ?
Upvotes: 6
Views: 5612
Reputation: 925
<?php
class Product extends Eloquent {
protected $with = array('category');
//protected $appends = array('category');
public function category()
{
return $this->belongsTo('Models\Category',
'category_id');
}
}
Define a $with
property instead of $appends
property. It is an eager load.
Upvotes: 8