This commit is contained in:
2020-08-11 20:23:49 +05:00
parent be66690453
commit 44199d5637
2 changed files with 31 additions and 28 deletions

View File

@@ -48,19 +48,21 @@ class ScrapeSunCommand extends Command
foreach ($articles as $article) { foreach ($articles as $article) {
// Attach the relationship between source and article and return the curren article instance // 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"], "title" => $article["title"],
"url" => $article["url"], "url" => $article["url"],
"author" => $article["author"], "author" => $article["author"],
"featured_image" => $article["image"], "featured_image" => $article["image"],
"body" => $article["content"], "body" => $article["content"],
"guid" => $article["guid"],
"published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"),
"meta" => [ "meta" => [
"title" => $article["og_title"] "title" => $article["og_title"]
] ]
]); ]
);
@@ -70,7 +72,6 @@ class ScrapeSunCommand extends Command
$topicModel->articles()->syncWithoutDetaching($articleModel); $topicModel->articles()->syncWithoutDetaching($articleModel);
}); });
} }
} }
} }

View File

@@ -48,19 +48,21 @@ class ScrapeThiladhunCommand extends Command
foreach ($articles as $article) { foreach ($articles as $article) {
// Attach the relationship between source and article and return the curren article instance // 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"], "title" => $article["title"],
"url" => $article["url"], "url" => $article["url"],
"author" => $article["author"], "author" => $article["author"],
"featured_image" => $article["image"], "featured_image" => $article["image"],
"body" => $article["content"], "body" => $article["content"],
"guid" => $article["guid"],
"published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"), "published_date" => Carbon::parse($article["date"])->format("Y-m-d H:i:s"),
"meta" => [ "meta" => [
"title" => $article["og_title"] "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"]]);