0
我正在使用Eloquent Repository通过ID获取“菜单”,并返回所有关联的“菜单项”。这工作正常,但我有一个问题重新排序他们的领域之一的'menuitems'。所以,我目前做的:Eloquent订购相关数据
$menu = $this->menuRepo->getById($id, 'menuitems');
它调用雄辩回购中此功能:
public function getById($id, $with = false)
{
if ($with)
{
return $this->model->withTrashed()->with($with)->findOrFail($id);
}
return $this->model->withTrashed()->findOrFail($id);
}
该函数将整个系统中使用,所以最好我想留下,因为它是 - 或将需要改变它,以便它不会在所有当前的用法中被破坏。但即便如此,当我尝试添加一个
->orderBy('name')
在那里,它适用于'menu'而不是'menuitems'。
的重复[Laravel雄辩:如何订购相关车型的结果(HTTP://计算器。 com/questions/25700529/laravel-eloquent-how-to-order-results-of-related-models#25701143) – 2014-09-30 10:02:58
谢谢,我确实有一个很好的搜索,但这个问题似乎已经滑倒了网络。 – Quinny 2014-10-01 14:47:10