Running the todays pick on a transformer
This commit is contained in:
@@ -9,7 +9,7 @@ use App\Http\Resources\ArticleResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class TodaysPick extends Controller
|
||||
{
|
||||
{
|
||||
/**
|
||||
* __invoke
|
||||
*
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user