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