Files
2026-06-14 00:05:16 +03:00

33 lines
1001 B
PHP

<?php
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
{
// Путь к вашему SQL файлу
$path = database_path('seeders/scripts/places.sql');
if (!File::exists($path)) {
$this->command->error("Файл не найден: {$path}");
return;
}
// Читаем содержимое файла
$sql = File::get($path);
// Выполняем SQL запрос (unprepared позволяет выполнять множественные INSERT)
try {
DB::unprepared($sql);
//$this->command->info('Данные из SQL файла успешно загружены!');
} catch (\Exception $e) {
$this->command->error("Ошибка при выполнении SQL: " . $e->getMessage());
}
}
}