public static function getPrimaryMuscleGroupedByExercise() { return Exercise::join('muscles', 'exercises.primary_muscle_id', '=', 'muscles.id')->groupBy('exercises.primary_muscle_id')->orderBy('muscles.name')->get(['muscles.id', 'muscles.name', \DB::raw('count(exercises.primary_muscle_id) as count_of_exercises')]); }
/** * Responds to requests to GET /api/exercises */ public function getList() { $exercises = Exercise::orderBy('name')->get(['id', 'name', 'slug']); return response()->json($exercises); }