How To Store Record In Diffrent Database In Laravel 8?

Laravel 8

Nicesnippets

28-12-2021


How To Store Record In Diffrent Database In Laravel 8?

Hi Dev,

In this article Laravel how to store record in diffrent database. Sometimes we need multiple databases in our system to work with and laravel is capable of doing this.

You store some records on different database so make this code and store the record.

With no more complexity, in this article is pretty easy to implement you will find the exact changes you want to make in your system.

Let’s start implementing dynamic database connection tutorial laravel.

Please follow steps to integrate the laravel database connection.

Solution


//Store record in 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...


Recommended Posts