
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
- Conditional where clause in Laravel
- Undefined property: stdClass::$title
- After image selected get validation error in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Retain selected value of select box in Laravel
- Laravel route redirect not working
- Setup laravel project with docker
- Get duplicate records in laravel
- The use statement with non-compound name 'DB' has no effect
- Session Doesn't Work on Redirect
- Laravel order by date not working
- How to change default timestamp fields name in Laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to pass data to multiple partial view files in laravel
- Send post data from controller to view
- How to pass link from controller to view in laravel on ajax call
- How to get all route list
- Call to undefined method App\Models\User::follow()
- How to prevent host header attack in Laravel
- How to remove P tag from CkEditor in Laravel?
- Delete records with relationship in laravel
- Get count of filter data, while return a small set of records
- Laravel save object to database
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- If no route matched route::fallback in laravel