How to Run SQL File or query In Laravel Seeder?

Admin   Laravel   427  2021-03-15 13:50:06

Hi Guys,

In this example,I will learn you how to run sql file or query in laravel can easy run sql file or query in laravel seeder.

In this example,I will create sql folder in public and store to sql can bellow this code in your first run bellow command for create "SqlFileSeeder" seeder.

Example :

First create a seeder file by artisan command.

Create Seeder :


php artisan make:seeder SqlFileSeeder

After run above command successfully, you will be found new created file database/seeds/SqlFileSeeder.php file and some sample data like as bellow:




use Illuminate\Database\Seeder;

class SqlFileSeeder extends Seeder



* Run the database seeds.


* @return void


public function run()


$path = public_path('sql/File.sql');

$sql = file_get_contents($path);




Now we are ready to run above seeder using bellow command:

Run Seeder:


php artisan db:seed --class=SqlFileSeeder

It will help you....