01-May-2023
.
Admin
Hi Dev,
In this article Laravel how to store records in different databases. Sometimes we need multiple databases in our system to work with and Laravel is capable of doing this.
You store some records on different databases so make this code and store the record.
With no more complexity, this article is pretty easy to implement you will find the exact changes you want to make in your system.
Let’s start implementing the dynamic database connection tutorial Laravel.
Please follow the steps to integrate the Laravel database connection.
Download Laravel
Let us begin the tutorial by installing a new Laravel application. if you have already created the project, then skip the following step.
composer create-project laravel/laravel example-app
Solution
//Store record in the first database
User::create($input);
//Store record in different database
$userModel = new User();
$userData = $userModel->setConnection('mysql2')
->create($input);
I hope it will help you...
#Laravel 10