Laravel 5.6 Eloquent Optimize A query

0

I need to optimize this in the model

public function getPointStatsByUserId($id){
    return array(
        'total_win' => Trade::where('point' , '>', '0')
            ->where('user_id' , $id)
            ->sum('point'),
        'total_lose' => Trade::where('point' , '<', '0')
            ->where('user_id' , $id)
            ->sum('point')
    );
}

You are making 2 queries to the database, I would like to know if it is possible to do it in just one query ... Thanks.

    
asked by kevin au tam 02.06.2018 в 03:44
source

0 answers