/** * Checks if there are any child Predmeti or Kategorije for the user * with id equal to $djelatnik_id * @param int $djelatnik_id Id of the user * @return boolean */ private function hasChildrenFor($djelatnik_id) { if (Predmet::select('id', 'ime')->where('kategorija_id', '=', $this->id)->withUser($djelatnik_id)->count() > 0) { return true; } $kategorije = Kategorija::where('nadkategorija_id', '=', $this->id)->whereRaw('nadkategorija_id != id')->get(); foreach ($kategorije as $kategorija) { if ($kategorija->hasChildrenFor($djelatnik_id)) { return true; } } return false; }