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
- Setup laravel project with docker
- Route group with URI prefix using middleware and route name prefixes
- Submit form without CSRF token in Laravel
- Conditional validation in laravel
- Redirect to previous page or url in laravel
- How to validate website url in laravel using validaiton
- How to run a specific seeder class in laravel
- Undefined property: stdClass::$title
- How to insert dynamic value to additional column in pivot table in laravel
- How to pass query string to url in laravel
- How to add unique records in pivot columns of Laravel pivot table
- How to create laravel project using jetstream
- Get the post details if it has at least one comment in comments table
- How to display user profile after login in laravel
- Touch parent updated_at in Laravel
- How to create new user without form submission in laravel
- Show old value while editing the form in Laravel
- Json encode method in laravel
- How to get the random value form a specific column in laravel ?
- Laravel specific table Migration
- How to send email in Laravel 11
- Insert Comma Separated Values in laravel
- Docker important commands to run laravel application with docker
- Retrieve count of nested relationship data in Laravel
- Class 'App\Http\Controllers\User' not found