From 44199d563707fe99fcbbe33e12e6bcdeb34153c9 Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Tue, 11 Aug 2020 20:23:49 +0500 Subject: [PATCH] Bug fix --- app/Console/Commands/ScrapeSunCommand.php | 31 ++++++++++--------- .../Commands/ScrapeThiladhunCommand.php | 28 +++++++++-------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/ScrapeSunCommand.php b/app/Console/Commands/ScrapeSunCommand.php index d77f284..ada1d46 100644 --- a/app/Console/Commands/ScrapeSunCommand.php +++ b/app/Console/Commands/ScrapeSunCommand.php @@ -48,29 +48,30 @@ class ScrapeSunCommand extends Command foreach ($articles as $article) { // Attach the relationship between source and article and return the curren article instance - $articleModel = $source->articles()->firstOrCreate([ - "title" => $article["title"], - "url" => $article["url"], - "author" => $article["author"], - "featured_image" => $article["image"], - "body" => $article["content"], - "guid" => $article["guid"], - "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), - "meta" => [ - "title" => $article["og_title"] + $articleModel = $source->articles()->firstOrCreate( + ["guid" => $article["guid"]], + [ + "title" => $article["title"], + "url" => $article["url"], + "author" => $article["author"], + "featured_image" => $article["image"], + "body" => $article["content"], + "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), + "meta" => [ + "title" => $article["og_title"] + ] + ] + ); - ]); - - collect($article["topics"])->each(function($topic) use ($articleModel) { + collect($article["topics"])->each(function ($topic) use ($articleModel) { - $topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]],["name" => $topic["name"]]); + $topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]], ["name" => $topic["name"]]); $topicModel->articles()->syncWithoutDetaching($articleModel); }); - } } } diff --git a/app/Console/Commands/ScrapeThiladhunCommand.php b/app/Console/Commands/ScrapeThiladhunCommand.php index 882d427..c7d86c4 100644 --- a/app/Console/Commands/ScrapeThiladhunCommand.php +++ b/app/Console/Commands/ScrapeThiladhunCommand.php @@ -48,22 +48,24 @@ class ScrapeThiladhunCommand extends Command foreach ($articles as $article) { // Attach the relationship between source and article and return the curren article instance - $articleModel = $source->articles()->firstOrCreate([ - "title" => $article["title"], - "url" => $article["url"], - "author" => $article["author"], - "featured_image" => $article["image"], - "body" => $article["content"], - "guid" => $article["guid"], - "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), - "meta" => [ - "title" => $article["og_title"] - ] + $articleModel = $source->articles()->firstOrCreate( + ["guid" => $article["guid"]], + [ + "title" => $article["title"], + "url" => $article["url"], + "author" => $article["author"], + "featured_image" => $article["image"], + "body" => $article["content"], + "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), + "meta" => [ + "title" => $article["og_title"] + ] - ]); + ] + ); collect($article["topics"])->each(function ($topic) use ($articleModel) { - $topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]],["name" => $topic["name"]]); + $topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]], ["name" => $topic["name"]]); $topicModel->articles()->syncWithoutDetaching($articleModel); });