大佬教程收集整理的这篇文章主要介绍了php-以雄辩的关系进行排序,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一张桌子:
>分析,列(id,名称,game_id(FK));
>游戏,栏目(id,名称,round_id(FK));
>圆,列(id,圆);
我需要按(round_id)获取所有分析订单记录.
我尝试Analyses :: orderBy(’round_id’)-> get(),但不起作用;
解决方法:
首先,您的分析表中没有该列
要进行订购,您必须将其添加到您的关系中(假设他们已正确完成)
分析模型
public function games()
{
return $this->hasmany(Game::class)->orderBy('round_id'); //see? we can add orderBy to the relation
}
游戏模型
public function rounds()
{
return $this->hasmany(Round::class); // i dont kNow if its manytomany for eal, im just trying to explain
}
现在,您可以使用像这样的eagerloading来获得游戏的所有分析结果并进行回合
$test = Analyses::with('games.round')->get();
$test = Analyses::with('games.round')->orderby('game_id')->get();
在上述示例中,您将按game_id进行分析排序,并且每个Analyze中的游戏将按round_id排序
我希望这是你想要做的
以上是大佬教程为你收集整理的php-以雄辩的关系进行排序全部内容,希望文章能够帮你解决php-以雄辩的关系进行排序所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。