php - How can I write this query with Eloquent

one text

Solution:

From what I understood I think this is what you are looking for, try it and tell me:


$orders = DB::table('likes')
                ->select('likeable_id', DB::raw('SUM(liked) as likes'), DB::raw('SUM(!liked) as dislikes'))
                ->groupBy('likeable_id')
                ->get();

You can get more information from the laravel Database documentation Query Builder here:

Source