-1

在下面的代码中,如果我删除我的“解决方法”,我会得到一个 user_name 列,我如何在 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"));
4

1 回答 1

0

文档中有

$users = DB::table('users')->select('name as user_name')->get();

如果你设置一个键值变量而不是“user_name”它应该做你想要的?

再见

于 2013-07-23T13:58:53.680 回答