/** * @return array */ private function getOverviewData() { $archive = $this->post->where('publish_date', '<=', date('Y-m-d H:i:s'))->orderBy('publish_date', 'DESC')->get()->groupBy(function ($query) { return Carbon::parse($query->publish_date)->format('F Y'); }); $data = ['categories' => $this->category->all(), 'tags' => $this->tag->all(), 'archives' => $archive]; return $data; }
/** * Build a post object when there * is a cached post so we can put * the data back in the form * * @return object */ private function buildPostObject() { $hash = $this->auth_user->hash; $cached_post = $this->cache->get("autoSavedPost-{$hash}"); $post = []; $post['hash'] = ''; $post['title'] = $cached_post['title']; $post['slug'] = $cached_post['slug']; $post['content'] = $cached_post['content']; $post['publish_date'] = $cached_post['publishdate']; $post['status_id'] = $this->status->byHash($cached_post['status'])->id; $post['visibility_id'] = $this->visibility->byHash($cached_post['visibility'])->id; $post['reviewer_id'] = $this->user->byHash($cached_post['reviewer'])->id; $post['category_id'] = $this->category->byHash($cached_post['category'])->id; $post['tag'] = $this->buildTagsArrayForPostObject($cached_post['tags']); return objectify($post); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $segment = $this->segment(3); $id = isset($segment) ? $this->category->byHash($this->segment(3))->id : 0; return ['name' => "required|unique:categories,name,{$id}|min:3|max:45"]; }
/** * 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; }