I am having little trouble about checking the DB in Laravel. I have scraped data and inserting those into DB. But before inserting progress. I want to check are there any same data or not (for example same url). If there is same url. Then avoid inserting that data.
what I have done so far is right below.
$i = 0;
$database = [];
foreach($placeUrls as $k => $urls) {
$database = [
"place_id" => $k,
"website" => "a-site",
"place_name" => $names[$k],
"url" => $urls,
];
if ($plan = Plan::where("url", "=", $urls)->first()) {
if ($plan->url != $database["url"]) {
$this->line("plan inserted");
Plan::insertGetId($database);
}
}
$i++;
}
But the checking part is not correct. How can I fix it?