Laravel在查询中删除“`”符号

时间:2015-06-09 05:46:38

标签: laravel laravel-5

我正在使用laravel 5.我试图将以下查询放在我的控制器中。

i

但它给出的输出就像这样

$projects = DB::table('projects AS prj')
                ->join('customers AS cus', 'prj.customerid', '=', 'cus.custid')
                ->leftjoin('file_assocs AS fa', 'prj.prjid', '=', 'fa.id')
                ->groupBy('fa.id','prj.prjid')
                ->select('count(fa.id) as filecount', 'prj.name as proj_name', 'prj.prjdesp', 'cus.name as customer_name')
                ->get();

这不是我的输出。因为在我的select `count(fa`.`id)` as `filecount`, `prj`.`name` as `proj_name`, `prj`.`prjdesp`, `cus`.`name` as `customer_name` from `projects` as `prj` inner join `customers` as `cus` on `prj`.`customerid` = `cus`.`custid` left join `file_assocs` as `fa` on `prj`.`prjid` = `fa`.`id` group by `fa`.`id`, `prj`.`prjid` 中显示为

count(fa.id)

所以它显示错误。有没有办法删除laravel中的“`”符号?

1 个答案:

答案 0 :(得分:2)

使用DB::raw()

$projects = DB::table('projects AS prj')
    ->join('customers AS cus', 'prj.customerid', '=', 'cus.custid')
    ->leftjoin('file_assocs AS fa', 'prj.prjid', '=', 'fa.id')
    ->groupBy('fa.id','prj.prjid')
    ->select(DB::raw('count(fa.id) as filecount, prj.name as proj_name, prj.prjdesp, cus.name as customer_name'))
    ->get();