V
V
Vit2016-08-15 16:23:11
Laravel
Vit, 2016-08-15 16:23:11

How to create a database entry using Eloquent?

There are two connections in the settings: local database and remote. You need to create an entry in the remote.

$model = new \App\Models\Setting();
$model->setConnection($request->dataset['connection']);
$model->create($request->all());

I specify a specific connection from the settings. As a result, the record is created in the local. The problem is only with the create() method. In all other methods, all data in the model comes from a remote database.
Before the $model->create method, I specifically dumped the model:
65439a2b4f9b4a29bc8448024729b51a.png
The correct connection is specified, but the model adds an entry using the default connection. How to fix this error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-08-15
@reech

The create method is static.
source code .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question