72 lines
2.7 KiB
PHP
72 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Article;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
/**
|
|
* Handle the incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function __invoke(Request $request)
|
|
{
|
|
$todays_pick = Cache::remember('home.todayspick', 600, function () {
|
|
return Article::with('topics', 'source')
|
|
->whereDate('published_date', Carbon::today())
|
|
->inRandomOrder()
|
|
->take(8)
|
|
->get()
|
|
->transform(function ($article) {
|
|
return [
|
|
"id" => $article->id,
|
|
"title" => $article->title,
|
|
"url" => $article->url,
|
|
"author" => $article->author,
|
|
"featured_image" => $article->featured_image,
|
|
"published_date" => $article->published_date,
|
|
"meta" => $article->meta,
|
|
"guid" => $article->guid,
|
|
"source" => $article->source,
|
|
"topics" => $article->topics,
|
|
];
|
|
});
|
|
//->unique('source.name')->values();
|
|
});
|
|
|
|
$covid19 = config("karudhaas.topic_filters.covid19");
|
|
$covid19_articles = Cache::remember("home.articles.covid19", 600, function () use ($covid19) {
|
|
return Article::with('source')->whereHas('topics', function ($q) use ($covid19) {
|
|
$q->whereIn('slug', ['mndf']);
|
|
})->latest('published_date')->limit(5)->get();
|
|
});
|
|
|
|
$business = config("karudhaas.topic_filters.business");
|
|
$business_articles = Cache::remember("home.articles.business", 600, function () use ($business) {
|
|
return Article::with('source')->whereHas('topics', function ($q) use ($business) {
|
|
$q->whereIn('slug', ['mndf']);
|
|
})->latest('published_date')->limit(4)->get();
|
|
});
|
|
|
|
$sports = config("karudhaas.topic_filters.sports");
|
|
$sports_articles = Cache::remember("home.articles.sports", 600, function () use ($sports) {
|
|
return Article::with('source')->whereHas('topics', function ($q) use ($sports) {
|
|
$q->whereIn('slug', ['mndf']);
|
|
})->latest('published_date')->limit(4)->get();
|
|
});
|
|
|
|
return view('home', [
|
|
"todays_pick" => $todays_pick,
|
|
"covid19_articles" => $covid19_articles,
|
|
"business_articles" => $business_articles,
|
|
"sports_articles" => $sports_articles
|
|
]);
|
|
}
|
|
}
|