
Seed database using SQL file in Laravel
Created at 07-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
- Send id with route Laravel
- Wheredate in laravel not working
- Import/Use Storage facade in laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Run artisan command to generate key in laravel
- How to display validation error in laravel
- How to pass query string to url in laravel
- Undefined property: stdClass::$title
- Composer create project laravel/laravel example app
- Attempt to read property "avatar" on null in Laravel
- How to automatically update the timestamp of parent model in Laravel
- The use statement with non-compound name 'DB' has no effect
- How to validate URL with https using regex in laravel
- Laravel get single row by id
- Get last week data in Laravel
- Insert data with form validation using ajax in laravel
- How to remove package from laravel
- OrderBy on Eloquent relationships method in Laravel
- Get content from web URL in laravel
- Get last record from table in laravel
- How to get user information using hootlex/laravel-friendships package in laravel
- How to display 1 day ago in comments in laravel view
- Database transactions in laravel
- How to validate form input data in laravel
- Define variable and use in Laravel controller method