/**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $hash = $this->input('hash');
     $id = !empty($hash) ? $this->post->byHash($hash)->id : 0;
     $protected_visibility = $this->visibility->whereName('Protected')->first()->hash;
     return ['title' => 'required|min:2|max:100', 'slug' => "required|unique:posts,slug,{$id}|min:2|max:120", 'reviewer' => 'exists:users,hash', 'post' => 'required', 'category' => 'required|exists:categories,hash', 'publishdate' => 'required|date_format: d-m-Y H:i', 'password' => "required_if:visibility,{$protected_visibility}"];
 }
 /**
  * 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);
 }
 public function run()
 {
     Visibility::create(["hash" => blogify()->makeHash('visibility', 'hash', true), "name" => "Public"]);
     Visibility::create(["hash" => blogify()->makeHash('visibility', 'hash', true), "name" => "Protected"]);
     Visibility::create(["hash" => blogify()->makeHash('visibility', 'hash', true), "name" => "Private"]);
 }