Laravel 9 Store Record In Diffrent Database Example

Apr 15, 2022 . Admin

Hello Dev,

Now let's see example of how to store record in different database example. We will check how to store record in different database. This is a short guide on store record in different database in laravel 9. Let's get started with how to store record in different database in laravel 9.

Here i will give you many example how to store record in different database using laravel 9.

Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Solution
//Store record in first database
User::create($input);

//Store record in different database
$userModel = new User();
$userData = $userModel->setConnection('mysql2')
            ->create($input);

It will help you...

#Laravel 9