$array = filmMoonwalk::chunk(200, function($films){
foreach ($films as $value) {
$filmFind = Film::where('title_ru', $value->title_ru)->first();
if($filmFind == null){
for ($i=1; $i <= 4; $i++) {
$newFilm = new Film();
$newFilm->kinopoisk_id = $value->kinopoisk_id;
$newFilm->title_ru = $value->title_ru;
$newFilm->title_en = $value->title_en;
$newFilm->year = $value->year;
$newFilm->genre = $value->genre;
$newFilm->thumbnail = $value->thumbnail;
$newFilm->description = $value->description;
$newFilm->rating = $value->rating;
$newFilm->tagline = $value->tagline;
$newFilm->country = $value->country;
$newFilm->actors = $value->actors;
$newFilm->token = $value->token;
$newFilm->iframe_url = $value->iframe_url;
$newFilm->translator = $value->translator;
$newFilm->save();
$deleteFilm = filmMoonwalk::find($value->id)->delete();
echo 'Успешно. ' . PHP_EOL;
break;
}
}
}
});
$array = filmMoonwalk::chunk(200, function($films){
$j = 0;
foreach ($films as $value) {
if($j>4) break;
$j++;
$filmFind = Film::where('title_ru', $value->title_ru)->first();
if($filmFind == null){
$newFilm = new Film();
$newFilm->kinopoisk_id = $value->kinopoisk_id;
$newFilm->title_ru = $value->title_ru;
$newFilm->title_en = $value->title_en;
$newFilm->year = $value->year;
$newFilm->genre = $value->genre;
$newFilm->thumbnail = $value->thumbnail;
$newFilm->description = $value->description;
$newFilm->rating = $value->rating;
$newFilm->tagline = $value->tagline;
$newFilm->country = $value->country;
$newFilm->actors = $value->actors;
$newFilm->token = $value->token;
$newFilm->iframe_url = $value->iframe_url;
$newFilm->translator = $value->translator;
$newFilm->save();
$deleteFilm = filmMoonwalk::find($value->id)->delete();
echo 'Успешно. ' . PHP_EOL;
}
}
});