Laravel 4.1 remove pivot attributes from response

Use the $hidden property of the model, you can add attributes or relations to it and the pivot is basicly acts as a relation.

class Foo extends Eloquent
{
    protected $hidden = array('pivot');

    public function bars()
    {
        return $this->belongsToMany('Bar');
    }
}

If you want to remove just any one column from the response, then you can try something like this:

In you Model:

public function toArray()
{
    $attributes = $this->attributesToArray();
    $attributes = array_merge($attributes, $this->relationsToArray());
    unset($attributes['pivot']['user_id']);
    return $attributes;
}

This way you will get only attribute required.

Tags:

Laravel 4