public function delete($id)
 {
     $category = PostCategory::findOrFail($id);
     $id = $category->id;
     $category->delete();
     return redirect('admin/blog/categories/' . $id . '/posts');
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('admin.partials.navbar', function ($view) {
         $postCategories = PostCategory::all();
         return $view->with(compact('postCategories'));
     });
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::first();
     if (!$user) {
         $this->error('No user to import articles to');
         return;
     }
     $archives = PostCategory::where('name', 'archives')->first();
     if (!$archives) {
         $archives = PostCategory::create(['name' => 'archives', 'description' => 'old posts from prev site']);
     }
     $this->archiveId = $archives->id;
     $upperBound = intval($this->ask('What is the upper bound for the article ids?'));
     $articlesToFetch = collect(ImportResult::getMissingIdsUpToLimit($upperBound));
     $articlesToFetch->each(function ($id) use($user) {
         try {
             $reader = $this->articleReader->getPage($id);
             $this->import($reader, $id, $user);
             ImportResult::create(['article_id' => $id, 'imported' => 1]);
         } catch (\Exception $e) {
             $this->error('Failed on article ' . $id . ' : ' . $e->getMessage());
             ImportResult::create(['article_id' => $id, 'imported' => 0]);
         }
     });
 }
 public function articleCount()
 {
     $categories = PostCategory::all();
     $colours = RandomColor::many($categories->count(), ['hue' => 'blue']);
     return $categories->map(function ($category, $index) use($colours) {
         return ['value' => $category->posts->count(), 'color' => $colours[$index], 'highlight' => '#1D976C', 'label' => $category->name];
     })->toArray();
 }
 public function dashboard()
 {
     $totalVisitors = LaravelAnalyticsFacade::getVisitorsAndPageViews(30)->reduce(function ($carry, $day) {
         return $day['visitors'] + $carry;
     }, 0);
     $categories = PostCategory::with(['posts' => function ($query) {
         $query->where('published', 1);
     }])->get();
     return view('admin.pages.dashboard')->with(compact('categories', 'totalVisitors'));
 }
 public function showBlog($categorySlug = null)
 {
     if ($categorySlug) {
         $category = PostCategory::findBySlug($categorySlug);
         $posts = $category->posts()->where('published', 1)->orderBy('published_at', 'desc')->simplePaginate(10);
         $filters = PostCategory::with(['posts' => function ($query) {
             $query->where('published', 1);
         }])->where('slug', '<>', $categorySlug)->get();
     } else {
         $category = $this->makeDefaultCategory();
         $posts = Post::where('published', 1)->orderBy('published_at', 'desc')->simplePaginate(10);
         $filters = PostCategory::with(['posts' => function ($query) {
             $query->where('published', 1);
         }])->get();
     }
     return view('front.blog.index')->with(compact('category', 'posts', 'filters'));
 }
Beispiel #7
0
 public function storePost($data, $categoryId)
 {
     $category = PostCategory::findOrfail($categoryId);
     return $this->posts()->create(array_merge($data, ['post_category_id' => $category->id]));
 }
 public function setCategory($id, Request $request)
 {
     $category = PostCategory::findOrFail($request->new_category_id);
     Post::findOrFail($id)->attachTo($category);
     return redirect('admin/blog/categories/' . $category->id . '/posts');
 }