I had this solution working well in Laravel 5.3
$procedure = Procedure::findOrFail($id);
$attached_stages = $procedure->stages()->getRelatedIds()->toArray();
Procedure
public function stages()
{
return $this->belongsToMany('App\Models\Stage', 'procedure_stage', 'procedure_id', 'stage_id')->withPivot('id','status')->withTimestamps();
}
Call to undefined method Illuminate\Database\Query\Builder::getRelatedIds()
getRelatedIds
to get ids array you can use pluck function
$procedure->stages()->pluck('stages.id')->toArray();