diff --git a/app/Console/Commands/ScrapeMihaaruCommand.php b/app/Console/Commands/ScrapeMihaaruCommand.php index 9ca85e3..0d40c00 100644 --- a/app/Console/Commands/ScrapeMihaaruCommand.php +++ b/app/Console/Commands/ScrapeMihaaruCommand.php @@ -47,13 +47,13 @@ class ScrapeMihaaruCommand extends Command foreach ($articles as $article) { // Attach the relationship between source and article and return the curren article instance - $articleModel = $source->articles()->firstOrCreate([ + $articleModel = $source->articles()->firstOrCreate(["guid" => $article["guid"]], + [ "title" => $article["title"], "url" => $article["url"], "author" => $article["author"], "featured_image" => $article["image"], "body" => $article["content"], - "guid" => $article["guid"], "published_date" => $article["date"], "meta" => [ "title" => $article["og_title"] diff --git a/app/Http/Controllers/SourcesController.php b/app/Http/Controllers/SourcesController.php index ed616ff..7003b22 100644 --- a/app/Http/Controllers/SourcesController.php +++ b/app/Http/Controllers/SourcesController.php @@ -25,11 +25,11 @@ class SourcesController extends Controller * @param mixed $source * @return JsonResponse */ - public function show(Source $source) : JsonResponse + public function show(Source $source) { return response()->json([ 'source' => new SourceResource($source), - 'articles' => ArticleResource::collection($source->articles()->paginate(8)) + 'articles' => ArticleResource::collection($source->articles()->latest("published_date")->paginate(8)) ]); } }