我有 this在 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();
}
现在,迁移到 Laravel 5.4 后,我收到此错误:
Call to undefined method Illuminate\Database\Query\Builder::getRelatedIds()
好像是
getRelatedIds
已被删除。我的问题:
如何在 5.4 中获取数组?
先感谢您。
最佳答案
它已从 5.4 中删除(基本上,更改了名称,仅此而已),但是当我深入查看 belongToMany.php
时,您将它改成了另一个名称。文件。用这个
它应该能很好地工作。
$attached_stages = $procedure->stages()->allRelatedIds()->toArray();
希望这对您和其他将来会遇到该问题的人有所帮助,并查看这篇文章。
关于php - 从belongsToMany 关系中获取相关ID 数组 - Laravel 5.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053194/