dimanche 5 février 2017

Getting array of related IDs from a belongsToMany relation - Laravel 5.4

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.

My question:

how to get the array in 5.4?

Thank you in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kGUoNg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire