How To Update Diffrent Database Record in Laravel?

Apr 28, 2023 . Admin

Hi Guys,

In this article, we will discuss Laravel and how to update records in different MySQL databases using the Laravel framework PHP. Sometimes we need multiple databases in our system to work with and Laravel is capable of doing this.

You update some records on different databases so make this code and update 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 :
// update record in the first database 

// update record in different database
$userModel = new User();
$userData = $userModel->setConnection('mysql_default')
            ->where('id', 5)
            ->update(['name' => 'john']);

I hope it will help you...

#Laravel 10