Laravel sort Relationship(Laravel 排序关系)
本文介绍了Laravel 排序关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用相关表格对结果进行排序?
How can I sort my result with related tables?
我有这个表:Clients
和 Managers
(用户表)
I have this tables: Clients
and Managers
(users table)
Client.php
Users.php(默认 Laravel 的模型)
Users.php (default Laravel's model)
我的问题是如何查询要按经理姓名排序的表客户端.
My question is how can I query table clients to be sorted by Manager's name.
到目前为止,这是我的代码:
Here is my code so far:
如果我尝试按姓名排序,它会按客户姓名排序,但如果我尝试按联系人排序,则需要按用户(经理)姓名排序.
If I try to sort by Name it sorts OK by Clients name but if I try to sort by contact it needs to sort by User's (Manager's) name.
推荐答案
试试这个.
把它放到你的 if 语句中 if($sort == 'contact'){/***