You can hide pivot object from toJson() method on the related model and tweak the relationship definition to have desirec column visible on the main model:
// Category model
public function products()
{
return $this->belongsToManu('Product')->withPivot('desired_column as desired_column');
// this way you override aliasing the column to pivot_desired_column thus avoid it being attached to the pivot model
}
// Product model
protected $hidden = ['pivot'];
// execution
$category->products->toArray(); // the same for toJson()
// array(
// 0 => array(
// 'id' => '1',
// ....
// 'created_at' => '2014-04-10 19:54:30',
// 'updated_at' => '2014-04-10 19:54:30',
// 'desired_column' => 'some value from pivot'
// )
// ),
// ....
// )
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community