Seed database using SQL file in Laravel
Created at 08-Jan-2022 ,
By samar
Seed database using SQL file in Laravel
Through many examples, we will learn how to resolve the "Seed database using SQL file in Laravel".
You can seed database using SQL file in Laravel. You have to place the database in project root directory and call the DB::unprepared() method to seed the database. This is the simple way to seed a database in Laravel with a .sql dump file.-
Seed database using SQL file in Laravel
//1. Place database file (laravel8.sql in my case) in root directory of your project. //2. Use the below code snippet in routes\web.php and visit /seed-database url to seed database. Route::get('/seed-database', function(){ DB::unprepared( file_get_contents(base_path() . './laravel8.sql') ); }); //Note : You have to create the database and configure in application's environment variables.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Display success message in laravel
- Generate unique username in Laravel
- How to create laravel project using composer
- Get content from web URL in laravel
- How to insert dynamic value to additional column in pivot table in laravel
- How to decrypt laravel password
- Pass value from controller to model in laravel
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Sample .htaccess file and index.php file under public directory in laravel
- Insert values in pivot table dynamically in laravel
- How to get single column value in laravel
- Add a subselect based on relationship using withAggregate method
- Laravel 5.4 save data to database
- How to send email in Laravel 11
- How to get last month records in Laravel
- Split an Eloquent Collection by half in Laravel
- The use statement with non-compound name 'Auth' has no effect
- Call to undefined method App\Models\User::follow()
- FirstOrCreate() Not Inserting Model
- How to get specific columns using Laravel eloquent methods
- How to generate .env file for laravel?
- Json encode method in laravel
- How to display validation error in laravel
- How to Access Array in blade laravel
- How to get session in blade Laravel ?