public function getProjectsByCategoryKey($categoryKey = '', $limit = 0) { $projectCategory = ProjectCategory::where('key', $categoryKey)->first(); if (isset($projectCategory) && !is_null($projectCategory)) { if ($limit == 0) { return $projectCategory->projects()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get(); } else { return $projectCategory->projects()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take($limit)->get(); } } return []; }