public function findSuitableSlug($name, $currentId = false) { $slug = $this->nameToSlug($name); while ($this->doesSlugExist($slug, $currentId)) { $slug .= '-' . substr(md5(rand(1, 500)), 0, 3); } return $slug; }