diff --git a/app/Console/Commands/ScrapeDhuvasCommand.php b/app/Console/Commands/ScrapeDhuvasCommand.php new file mode 100644 index 0000000..fe82a71 --- /dev/null +++ b/app/Console/Commands/ScrapeDhuvasCommand.php @@ -0,0 +1,73 @@ +first(); + + $articles = (new DhuvasService)->scrape(); + + foreach ($articles as $article) { + + // Attach the relationship between source and article and return the curren article instance + $articleModel = $source->articles()->updateOrCreate(["guid" => $article["guid"]], + [ + "title" => $article["title"], + "url" => $article["url"], + "author" => $article["author"], + "featured_image" => $article["image"], + "body" => $article["content"], + "published_date" => $article["date"], + "meta" => [ + "title" => $article["og_title"] + ] + + ]); + + collect($article["topics"])->each(function($topic) use ($articleModel) { + $topicModel = Topic::firstOrCreate(["slug" => $topic["slug"]],["name" => $topic["name"]]); + + $topicModel->articles()->syncWithoutDetaching($articleModel); + }); + + } + } +}