Running the todays pick on a transformer

This commit is contained in:
2020-08-20 04:16:41 +05:00
parent bcd55d7349
commit 4e671f7ca0

View File

@@ -19,11 +19,25 @@ class TodaysPick extends Controller
*/
public function __invoke()
{
return Article::with('topics', 'source')
->whereDate('published_date', Carbon::today())
->inRandomOrder()
->take(8)
->get()
->unique('source.name')->values()->toArray();
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,
"source" => $article->source
];
})
->unique('source.name')
->values()
->toArray();
}
}