In this tutorial, we will learn Laravel Import Large SQL File using Seeder Example.

Hello Dev, let's see an example of how to import a large SQL file using seeder in laravel application.

Run below command to create seeder: 

php artisan make:seeder ImportTableSeeder

Create following file, database/seeders/ImportTableSeeder.php

namespace Database\Seeders;
use Illuminate\Database\Seeder;
class ImportTableSeeder extends Seeder
     * Run the database seeds.
     * @return void
    public function run()
        $sql = public_path('data.sql');
        $db = [
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE')
        exec("mysql --user={$db['username']} --password={$db['password']} --host={$db['host']} --database {$db['database']} < $sql");
        \Log::info('SQL Import Done');

Now run the below command:

php artisan db:seed --class=ImportTableSeeder

May this example help you.