/** * @return \jorenvanhocht\Blogify\Models\Post */ private function storeOrUpdatePost() { if (!empty($this->data->hash)) { $post = $this->post->byHash($this->data->hash); } else { $post = new Post(); $post->hash = $this->blogify->makeHash('posts', 'hash', true); } $post->slug = $this->data->slug; $post->title = $this->data->title; $post->content = $this->data->post; $post->status_id = $this->status->byHash($this->data->status)->id; $post->publish_date = $this->data->publishdate; $post->user_id = $this->user->byHash($this->auth_user->hash)->id; $post->reviewer_id = $this->user->byHash($this->data->reviewer)->id; $post->visibility_id = $this->visibility->byHash($this->data->visibility)->id; $post->category_id = $this->category->byHash($this->data->category)->id; $post->being_edited_by = null; if (!empty($this->data->password)) { $post->password = $this->hash->make($this->data->password); } $post->save(); $post->tag()->sync($this->tags); return $post; }
/** * Save the given category in the db * * @param CategoryRequest $request * @return \jorenvanhocht\Blogify\Models\Category */ private function storeOrUpdateCategory($request) { $cat = $this->category->whereName($request->name)->first(); if (count($cat) > 0) { $category = $cat; } else { $category = new Category(); $category->hash = $this->blogify->makeHash('categories', 'hash', true); } $category->name = $request->name; $category->save(); return $category; }
/** * @return void */ private function storeOrUpdateTags() { foreach ($this->tags as $tag_name) { $t = $this->tag->whereName($tag_name)->first(); if (count($t) > 0) { $tag = $t; } else { $tag = new Tag(); $tag->hash = $this->blogify->makeHash('tags', 'hash', true); } $tag->name = $tag_name; $tag->save(); array_push($this->stored_tags, $tag); $this->tracert->log('tags', $tag->id, $this->auth_user->id); } }
/** * @param \jorenvanhocht\Blogify\Requests\UserRequest $data * @param string $hash * @return array */ private function storeOrUpdateUser($data, $hash = null) { $password = null; if (!isset($hash)) { $password = $this->blogify->makeHash(); $user = new User(); $user->hash = $this->blogify->makeHash('users', 'hash', true); $user->password = $this->hash->make($password); $user->username = $this->blogify->generateUniqueUsername($data->name, $data->firstname); $user->lastname = $data->name; $user->firstname = $data->firstname; $user->email = $data->email; } else { $user = $this->user->byHash($hash); } $user->role_id = $this->role->byHash($data->role)->id; $user->save(); return ['user' => $user, 'password' => $password]; }