how to solve result from raw expression query builder in laravel 5.5

前端 未结 1 531
闹比i
闹比i 2021-01-24 03:47

How can I get the result as just

100.0%

in Laravel blade.php? When I use code raw expression in laravel 5.5 below:

$         


        
1条回答
  •  花落未央
    2021-01-24 04:23

    The ->get() method of \Illuminate\Database\Query\Builder return instance of \Illuminate\Support\Collection, In your case need get only one result. For this use ->first() method instead of ->get(). ->first() method return instance of stdClass and you can directly get your needed attribute

    For your case corrected code is.

    $jml_status_ap_all_pr = DB::table('aps')
        ->select(DB::raw('ROUND((COUNT(STATUS)/(SELECT COUNT(*) FROM aps))*100,1) as calc'))
        ->first()
        ->calc;
    

    0 讨论(0)
提交回复
热议问题