
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
- Get laravel version
- Send OTP using textlocal api in laravel
- Get today records in Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to generate .env file for laravel?
- Conditional validation in laravel
- Store logged in user details in session and display in view in laravel
- Laravel 9 pagination with search filter
- Run artisan command to generate key in laravel
- Convert input array to comma-separated string in laravel controller
- How to create event and listener in laravel ?
- How to get only time from created_at in laravel
- How to get last year records count with month wise in Laravel
- Display success message in laravel
- How to get path from current URL in Laravel
- On delete set foreign id column value null using migration in laravel 8
- Get last record from table in laravel
- How to get records in random order in laravel
- Trying to get property 'title' of non-object
- Pass variable from blade to controller Laravel
- Array to string conversion laravel Controller
- Laravel get count with where condition
- How to validate form input data in laravel
- Get latest record by created at in Laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement