在下面的代码中,如果我删除了我的“解决方法”,我得到一个用户名列,如何在get命令之前设置别名?有诀窍吗?
//Select
$qb = DB::table('log as l');
//Joins
$qb->join('user as u', 'l.user_id', '=', 'u.id');
//Orders
if($sort[0]["field"]=="user_name")// This is a workaround for my problem
$sort[0]["field"] = "u.name";
$qb->orderBy($sort[0]["field"],$sort[0]["dir"]);
//Wheres
Data::applyFilter($qb,$filters);
$total = $qb->count("l.id");
$qb->skip($skip)
->take($take);
$result = $qb->get(array("l.id", "l.action", "l.entity_type", "l.entity_id", "u.name as user_name", "l.datetime"));
答案 0 :(得分:0)
$users = DB::table('users')->select('name as user_name')->get();
如果你设置一个键值变量而不是“user_name”它应该做你想要的吗?
再见