2021年3月5日星期五

Inserting variable inside selectRaw

how to insert $TotalDistance inside selectRaw?

    public function totalPace()  {        $TotalDistance = $this->hasMany(Runners_List::class, 'run_list_id')->sum('distance'); //60 karon      $TotalPace = $this->hasMany(Runners_List::class, 'run_list_id')->selectRaw('SEC_TO_TIME( SUM(           TIME_TO_SEC( `pace` ) ) / '$TotalDistance') as total')->first();            return $TotalPace;  }  

It works if I replace $TotalDistance with just a number

https://stackoverflow.com/questions/66501207/inserting-variable-inside-selectraw March 06, 2021 at 08:25AM

没有评论:

发表评论