fixed event seeder
This commit is contained in:
@@ -4,52 +4,29 @@ namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class PlaceSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$tableName = 'places';
|
||||
// Путь к вашему SQL файлу
|
||||
$path = database_path('seeders/scripts/places.sql');
|
||||
|
||||
// Очищаем таблицу перед вставкой
|
||||
DB::table($tableName)->truncate();
|
||||
if (!File::exists($path)) {
|
||||
$this->command->error("Файл не найден: {$path}");
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
['id' => 1, 'name' => 'Ресторан "Мой Двор"', 'address' => 'г. Москва, м. Новогиреево, ул. Сталеваров, вл. 3л.', 'phone' => '+7 (495) 778-52-29', 'gps' => '55.758533|37.841869', 'url' => 'http://www.restoranmoydvor.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 2, 'name' => 'Бар Дефакто', 'address' => 'г. Москва, Большая Лубянка д.30/2', 'phone' => '+7 (495) 624-44-97', 'gps' => '55.766182|37.631424', 'url' => 'http://defaqto.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 3, 'name' => 'Ресторан "Serafina"', 'address' => 'г. Москва, Родчельская ул, 15/1', 'phone' => '+7 (495) 653-83-73', 'gps' => '55.756402|37.566715', 'url' => 'http://serafinarestaurant.ru', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 4, 'name' => 'клуб MUSIC TOWN', 'address' => 'г. Москва, ул.Каланчевская 33, м.Комсомольская', 'phone' => '+7 (495) 937-54-19', 'gps' => '55.776271|37.64892', 'url' => 'http://www.musictownclub.com/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 5, 'name' => 'Клуб "Релакс"', 'address' => 'г. Москва, ул.Мельникова, д.7', 'phone' => '+7 (495) 287-40-90', 'gps' => '55.725926|37.67351', 'url' => 'http://sevenclub7.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 6, 'name' => 'Клуб "Байконур"', 'address' => 'г. Москва, ул. Декабристов, д. 17 ', 'phone' => '+7 (925) 099 10-11', 'gps' => '55.865008|37.604784', 'url' => 'http://baikonur-club.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 7, 'name' => 'АНТРЕ бар', 'address' => 'г. Москва, ул.Мельникова д.7, метро: Пролетарская', 'phone' => '+7 (967) 297-26-97', 'gps' => '55.725926|37.67351', 'url' => 'http://vk.com/barantre', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 8, 'name' => 'FM-CLUB', 'address' => 'г. Москва, Земляной Вал д.60/28 или Николоямская д.28/60', 'phone' => '+7 (495) 502-99-21', 'gps' => '55.746907|37.654807', 'url' => 'http://afisha.yandex.ru/msk/places/2794/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 9, 'name' => 'Blur Cafe', 'address' => 'г. Москва, Большой Дровяной пер., д. 8 стр. 1', 'phone' => '+7 (495) 915-76-05', 'gps' => '55.744153|37.656924', 'url' => 'http://blurcafe.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 10, 'name' => 'Glastonberry Pub', 'address' => 'г. Москва, 1-ая Дубровская 13А, стр.1', 'phone' => '+7 (915) 217-96-89', 'gps' => '55.722856|37.675101', 'url' => 'http://www.glastonberrypub.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 11, 'name' => 'WHITE FOX Pub', 'address' => 'г. Истра, ул.Адасько, д.7к1', 'phone' => '+7 (916) 684-54-20', 'gps' => '55.912044|36.860026', 'url' => 'http://vk.com/irishpub_whitefox', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 12, 'name' => 'Doolin House', 'address' => 'г. Москва, Арбат 20', 'phone' => '+7 (495) 695-92-06', 'gps' => '55.750485|37.593378', 'url' => 'http://doolin-house.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 13, 'name' => 'Гранд Бурбон Стрит', 'address' => 'г. Москва, Потаповский пер., 5', 'phone' => '+7 (495) 625-94-24', 'gps' => '55.761692|37.640528', 'url' => 'http://www.grand-bourbon.ru', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 14, 'name' => 'Night Train', 'address' => 'г. Москва, 1-ый Угрешский проезд д. 7а, стр. 2 ', 'phone' => '+7 (925) 001-26-18 ', 'gps' => '55.716112|37.68881', 'url' => 'http://www.nighttrain.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 15, 'name' => 'Ресторан Бюрократ', 'address' => 'г. Москва, ул. Мневники, д. 13', 'phone' => '+7 (499) 191-16-08', 'gps' => '55.773334|37.484951', 'url' => 'http://www.burocratbeer.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 16, 'name' => 'Little Rock', 'address' => 'г. Москва, ул. Сельскохозяйственная, 15к4', 'phone' => '+7 (968) 845-74-63', 'gps' => '55.836729|37.638116', 'url' => 'http://vk.com/littlerockclub', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 17, 'name' => 'China Town', 'address' => 'г. Москва, Лубянский проезд, 25, стр. 1', 'phone' => '+7 (495) 623-61-63', 'gps' => '55.754873|37.634554', 'url' => 'http://chinatowncafe.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 18, 'name' => "Harat's Pub", 'address' => 'г. Калуга, ул. Достоевского, 25', 'phone' => '+7 (4842) 56-11-05', 'gps' => '54.512209|36.252153', 'url' => 'http://www.harats.ru/pubs/kaluga', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 19, 'name' => 'Швайн', 'address' => 'г. Москва, Лефортовский пер. 12/50', 'phone' => '+7 (499) 267-45-04', 'gps' => '55.769782|37.678713', 'url' => 'http://schwein.ru', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 20, 'name' => 'Jimi', 'address' => 'Москва, Спартаковская площадь, 16/15, стр. 17', 'phone' => '+7 (495) 053-18-88', 'gps' => '55.780664|37.634364', 'url' => 'http://jimiclub.ru', 'updated' => '2017-10-21 09:59:24', 'created' => now()],
|
||||
['id' => 21, 'name' => 'Travel Cafe', 'address' => 'г. Москва, ул. Верхняя Радищевская, д.7, стр.1', 'phone' => '+7 (495) 915-73-76', 'gps' => '55.744487|37.649539', 'url' => 'https://vk.com/club76897606', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 22, 'name' => 'Monaclub', 'address' => 'г. Москва, ул. Павла Корчагина, д.2А', 'phone' => '+7 (495) 776-09-93', 'gps' => '55.810836|37.655371', 'url' => 'http://monaclub.ru/', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 23, 'name' => 'Клуб Театр', 'address' => 'г. Москва, ул. Барклая, 6, строение 2', 'phone' => '8 (965) 446-60-26', 'gps' => '55.766581|37.663911', 'url' => 'https://vk.com/teatrmoscow', 'updated' => '2018-01-17 09:20:57', 'created' => now()],
|
||||
['id' => 24, 'name' => '#ММ77', 'address' => 'г. Москва, Волгоградский пр. 32к8', 'phone' => 'N/A', 'gps' => '55.722700|37.690685', 'url' => 'https://vk.com/motobarmm77', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 25, 'name' => 'Rock House', 'address' => 'г. Москва, Измайловское шоссе 71 корпус 5 (Е)', 'phone' => '+7 (495) 728-04-66', 'gps' => '55.789859|37.749280', 'url' => 'http://www.rock-house.ru', 'updated_at' => now(), 'created' => now()],
|
||||
['id' => 26, 'name' => 'Клуб ЛЕС', 'address' => 'Москва, Лесная, 30А', 'phone' => '+7 (965) 446-60-26', 'gps' => '55.783358|37.5963319', 'url' => 'http://www.lesmoscow.com', 'updated' => '2017-05-23 12:31:13', 'created' => '2017-05-23 12:31:13'],
|
||||
['id' => 27, 'name' => 'LiveStars', 'address' => 'Берсеневский пер. 5а ,стр.2', 'phone' => '8-968-884-71-60', 'gps' => '55.7414009|37.6101654', 'url' => 'http://www.livestarsclub.ru', 'updated' => '2017-09-03 16:37:42', 'created' => '2017-09-03 16:37:42'],
|
||||
['id' => 28, 'name' => 'Клуб Контора', 'address' => 'Москва, Варсонофьевский пер., д.1', 'phone' => '8 (499) 707-22-69', 'gps' => '55.752180|37.617985', 'url' => 'https://vk.com', 'updated' => '2018-01-17 09:10:22', 'created' => '2018-01-17 09:10:22'],
|
||||
['id' => 29, 'name' => 'Bar For Bikers', 'address' => 'Москва, Нижегородская, 32с5', 'phone' => '8 (499) 226-40-50', 'gps' => '55.737161|37.689490', 'url' => 'http://barforbikers.ru', 'updated' => '2018-11-05 13:29:51', 'created' => '2018-05-26 18:12:04'],
|
||||
['id' => 30, 'name' => 'Долина-Иволга', 'address' => 'Тверская область, Конаковский район, п/о «Энергетик»', 'phone' => '8 (499) 703 31 88', 'gps' => '56.6711037|36.6879069', 'url' => 'http://dolina-ivolga.ru', 'updated' => '2018-09-09 08:56:05', 'created' => '2018-09-09 08:56:05'],
|
||||
['id' => 31, 'name' => 'Бар мажор', 'address' => 'г. Калуга ул. Кирова 50', 'phone' => '8 (4842) 56-21-33', 'gps' => '54.513898|36.258700', 'url' => 'https://vk.com/bar_major', 'updated' => '2019-04-08 12:08:19', 'created' => '2019-04-08 12:05:09'],
|
||||
['id' => 32, 'name' => 'Б.О. Галактика', 'address' => 'База отдыха Галактика', 'phone' => '+7 (484) 396-72-83', 'gps' => '55.752180|37.617985', 'url' => 'https://www.galakticka.ru', 'updated' => '2019-04-17 21:02:37', 'created' => '2019-04-17 20:59:00'],
|
||||
];
|
||||
// Читаем содержимое файла
|
||||
$sql = File::get($path);
|
||||
|
||||
// Массовая вставка одним запросом
|
||||
DB::table($tableName)->insert($data);
|
||||
// Выполняем SQL запрос (unprepared позволяет выполнять множественные INSERT)
|
||||
try {
|
||||
DB::unprepared($sql);
|
||||
//$this->command->info('Данные из SQL файла успешно загружены!');
|
||||
} catch (\Exception $e) {
|
||||
$this->command->error("Ошибка при выполнении SQL: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user