Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$csv = Reader::createFromPath(database_path('seeds/sources/belgian-cities.csv'), 'r');
foreach ($stmt->process($csv) as $city) {
// Create a new province if not exists
$province = $provinces->firstOrCreate(['name' => $city['province']]);
// Create a new city in the database if not exists
$cityInformation = $cities->firstOrCreate([
// City information
'province_id' => $province->id, 'postal' => $city['postal'], 'name' => $city['name'], 'lat' => $city['lat'], 'lng' => $city['lng']
// Attach province to the create city
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.