public function run()
 {
     $pos = 0;
     foreach ($this->data as $category => $template) {
         $this->category->create(['title' => $category, 'slug' => str_slug($category), 'template' => $template, 'active' => true, 'position' => $pos]);
         $pos++;
     }
 }
 /**
  * Show posts from category
  *
  * @param Request $request
  * @param null $slug
  * @return \Illuminate\View\View
  */
 public function category(Request $request, $slug = null)
 {
     $category = !$slug ? $this->category->first() : $this->category->findBySlug($slug);
     if (!$category) {
         throw new NotFoundHttpException();
     }
     $posts = $this->post->findByCategory($category, $this->currentUser, 10);
     if ($request->has('ajax')) {
         return $this->jsonPagination($posts, $this->view('ajax.posts', compact('posts')));
     }
     return $this->view('post.list', compact('category', 'posts'));
 }
 /**
  * Process post categories
  *
  * @param Post $post
  * @param array $data
  */
 protected function processCategories(Post $post, array $data)
 {
     if ($data['type'] == 'gif') {
         $gifCategories = $this->category->findSlugsByTemplate('gif');
         $data['categories'] = array_merge($data['categories'], $gifCategories);
     }
     $categories = $this->category->findBySlugs($data['categories']);
     $this->post->addCategories($post, $categories);
     foreach ($categories as $category) {
         if ($category->template == 'nsfw') {
             $this->post->update($post, ['safe' => false]);
             break;
         }
     }
 }
 /**
  * Find category by id
  *
  * @param $id
  * @return \Smile\Models\Category
  */
 public function findById($id)
 {
     return $this->category->findById($id);
 }