Without Laravel:
Depending on which MYSQL client you are using (PhpMyAdmin, Workbench, etc.), if you already have the table created in the database, you can just import the file to the client and the client will do the rest for you. Search how to import a dump file for your specific MySQL client.
With Laravel:
What I do is
- I copy the query itself (the part that starts with INSERT INTO) in another file in the storage folder (let's say in
storage/app/country.sql
)
- In the seeder class now I get the content of the file which I insert with
DB::insert
// database/seeds/CountrySeeder.php
class CountrySeeder extends Seeder
{
public function run ()
{
$sql = file_get_contents(storage_path('app').'/country.sql');
DB::insert($sql);
}
}
Make sure the class is called in the DatabaseSeeder
class
// database/seeds/DatabaseSeeder.php
class DatabaseSeeder extends Seeder
{
public function run ()
{
$this->call([
// ...
CountrySeeder::class,
// ... other seeders
]);
}
}