I had this solution working well in Laravel 5.3
$procedure = Procedure::findOrFail($id);
$attached_stages = $procedure->stages()->getRelatedIds()->toArray();
In my Procedure
model:
public function stages()
{
return $this->belongsToMany('App\Models\Stage', 'procedure_stage', 'procedure_id', 'stage_id')->withPivot('id','status')->withTimestamps();
}
Now, after migrating to Laravel 5.4, I get this error:
Call to undefined method Illuminate\Database\Query\Builder::getRelatedIds()
Seems that the getRelatedIds
has been removed.
how to get the array in 5.4?
Thank you in advance.
to get ids array you can use pluck function
$procedure->stages()->pluck('stages.id')->toArray();