/** * @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(); }
/** * @param Request $request * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ public function index(Request $request) { $query = Post::with(['translations', 'tags', 'images', 'images.sizes' => function ($query) { $query->dimension(150); }, 'images.translations']); $value = $request->get('query'); $locale = $request->get('locale'); if (!empty($value)) { $query->whereHas('translations', function ($q) use($value, $locale) { $q->where('locale', $locale); $q->where(function ($q) use($value) { $q->where('title', 'like', '%' . $value . '%')->orWhere('content', 'like', '%' . $value . '%'); }); }); } return $query->paginate(); }
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]); }); }