/**
  * Handle the command.
  *
  * @param  CreateCategoryCommand  $command
  * @return void
  */
 public function handle(CreateCategoryCommand $command)
 {
     $active = 1;
     // $active = ($command->active === 'on') ? 1 : 0;
     $category_object = Categories::make($command->category, $active);
     $category = $this->repo->save($category_object);
     Event::fire(new CategoryWasCreated($category));
     return $category;
 }
Example #2
0
 public function getRelatedNewsByCategoryAndTags(Pages $page)
 {
     $category_ids = array_pluck($page->categories, 'id');
     $tag_ids = array_pluck($page->tags, 'id');
     if (count($category_ids) < 1) {
         $category_ids = [''];
     }
     if (count($tag_ids) < 1) {
         $tag_ids = [''];
     }
     $category_news = array_pluck(Categories::with('news.categories', 'news.tags')->whereIn('id', $category_ids)->get(), 'news');
     $tag_news = array_pluck(Tags::with('news.categories', 'news.tags')->whereIn('id', $tag_ids)->get(), 'news');
     if (count($category_news)) {
         $category_news = $category_news[0];
     }
     if (count($tag_news)) {
         $tag_news = $tag_news[0];
     }
     return array($category_news, $tag_news);
 }
Example #3
0
 public function getBySlug($slug)
 {
     return Categories::with('news')->where('slug', $slug)->first();
 }