/** * 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; }
/** * Gets the sets. * * @return \Illuminate\Database\Eloquent\Collection */ protected function getSets() { return Set::all(); }
/** * Get a set. * * @param int $id * * @return \Socializr\Models\Set */ protected function getSet($id) { try { return Set::with('shares', 'profile')->findOrFail($id); } catch (ModelNotFoundException $e) { throw new HttpErrorException(404, "Set {$id} doesn't exist!"); } }