/** * Returns a url safe `slug` that is unique. * * @param string $text unsage/nonunique slug * @param Integer $exists * * @return string Safe, unique slug String. */ private function slugify($text, $exists = null) { $text = Helper::formatSlug($text); $set = $this->findBySlug($text); $unique = false; if (!$set || $set->id === $exists) { $unique = true; return $text; } $i = 0; while (!$unique) { $i++; $set = $this->findBySlug($text . '-' . $i); if (!$set || $set->id === $exists) { $unique = true; } } return $text . '-' . $i; }
/** * Attaches all relational post data to the specified set. * * @param \Socializr\Models\Set $set Specified Set * @param string $type specifies the type of data to be attached * @param Array $data Data to be attached * * @return \Socializr\Models\Set Returns the set with all relational data attached */ protected function attachRelationships($set, $type, $data) { if ($type === 'SHARE') { $set->shares()->attach($data); } else { $profiles = []; foreach ($data as $key => $profile) { $profile['handle'] = !empty($profile['handle']) ? Helper::formatSlug($profile['handle']) : Helper::formatSlug($profile['title']); $profiles[] = new Profile($profile); } $set->profile()->saveMany($profiles); } return $set; }