/** * @param Post $post * @param PostRepositoryInterface $posts * @return string */ public function index(Post $post, PostRepositoryInterface $posts) { /* * images are lazyloaded in specific template file.. are they really? */ $posts = Post::with($posts->relations())->orderBy('created_at', 'desc')->paginate(); return $this->theme->render('blog.overview', ['posts' => $posts])->render(); }
protected function viewComposers() { /** @var Factory $view */ $this->app['view']->composer('Unify::layout.footers.*', function (View $view) { $posts = app('cache')->sear('footer-posts:' . app()->getLocale(), function () { $translations = PostTranslation::lastPublished()->take(3)->lists('post_id'); if ($translations->count() == 0) { return new Collection(); } $posts = Post::with(['translations', 'images', 'images.sizes'])->whereIn('posts.id', $translations->toArray())->get(); return $posts->sortBy('publish_at')->reverse(); }); $tweets = latest_tweets(); $view->with(['posts' => $posts, 'tweets' => $tweets]); }); $this->app['view']->composer('Unify::layout.widgets.clients', function (View $view) { $clients = app('cache')->sear('widget-clients', function () { return Client::has('images', '>', 0)->take(30)->get(); }); if ($clients->count()) { $amount = $clients->count() > 10 ? 10 : $clients->count(); $clients = $clients->shuffle()->random($amount); } $view->with('clients', $clients); }); $this->app['view']->composer('Unify::blog.sidebars.*', function (View $view) { //latest posts ? $posts = app('Modules\\Blog\\PostRepositoryInterface'); $latest = $posts->getLatestPosts(3); //problem with this is it can still show tags without content for the current locale $tags = \Modules\Tags\Tag::has('content')->limit(15)->get(); $view->with(['latest' => $latest, 'tags' => $tags]); }); $this->app['view']->composer('Unify::layout.widgets.recent-posts', function (View $view) { $posts = app('Modules\\Blog\\PostRepositoryInterface'); $latest = $posts->getLatestPosts(3); $view->with(['latest' => $latest]); }); $this->app['view']->composer('Unify::layout.widgets.portfolio-examples', function (View $view) { $projects = app('Modules\\Portfolio\\PortfolioRepositoryInterface'); $projects = $projects->getExamples(4); $view->with(['projects' => $projects]); }); }
/** * @return bool|Post */ public function handle() { $this->post->fill($this->input); return $this->post->save() ? $this->post : false; }
protected function listeners() { Post::observe('Modules\\Blog\\PostObserver'); }
/** * @param Request $request * @param Post $post */ public function batchUnpublish(Request $request, Post $post) { $ids = $request->get('posts', []); if (is_array($ids) && count($ids)) { $posts = $post->whereIn('posts.id', $ids)->get(); foreach ($posts as $post) { $translation = $post->translate($request->get('locale')); if ($translation) { $translation->publish_at = null; } $translation->save(); } } }
/** * @param Post $post */ public function creating(Post $post) { if (!$post->user_id) { $post->user()->associate($this->auth->user()); } }
/** * * $newsletter */ protected function getMaps() { $posts = new Collection(); $projects = new Collection(); $this->each(function ($widget) use($projects, $posts) { if ($widget->resource) { if ($widget->resource_type == Post::class) { $posts->push($widget->resource_id); } if ($widget->resource_type == Project::class) { $projects->push($widget->resource_id); } } if ($widget->other_resource) { if ($widget->other_resource_type == Post::class) { $posts->push($widget->other_resource_id); } if ($widget->other_resource_type == Project::class) { $projects->push($widget->other_resource_id); } } }); $posts = Post::whereIn('posts.id', $posts->all())->with(['translations', 'images', 'images.sizes'])->get(); $projects = Project::whereIn('portfolio_projects.id', $projects->all())->with(['translations', 'images', 'images.sizes'])->get(); return [$posts, $projects]; }