Hey, whats up!
I am working to developed a base structure for one of my SAAS application and the scenario is we need to seed good amount of data wither through Laravel seeded or from sql dump file. So, I want to do it with both – I want to run the SQL dump file through the Laravel seeder. So, here is the solution
First create a seeder file by artisan commandphp artisan make:seeder SqlSeeder
It will create a seeder file in database\seeds\SqlSeeder.php
And now put the below code into run() function in the SqlSeeder.php file$path = base_path() . '/database/seeds/data.sql';
$sql = file_get_contents($path);
DB::unprepared($sql);
$path: is the path of the dump data.sql file
$sql: storing data.sql file’s content (sql query) through file_get_contents() function.
And executing query at the 3rd line.
Now run the artisan commandphp artisan db:seed --class=SqlSeeder
***Magic*** 😀
Now check the database and thanks me by sharing and comment on this article. 😉