Skip to content

[5.4] Set connection while creating a model#17392

Merged
taylorotwell merged 2 commits into
laravel:5.4from
themsaid:modelCreationConnection
Jan 18, 2017
Merged

[5.4] Set connection while creating a model#17392
taylorotwell merged 2 commits into
laravel:5.4from
themsaid:modelCreationConnection

Conversation

@themsaid

@themsaid themsaid commented Jan 18, 2017

Copy link
Copy Markdown
Member

This PR adds the ability to set the desired connection to create the model on.

To save a model on a different connection you currently need to do something like:

$model = new User();

$model->setConnection('myConnection');

$model->save();

With this PR, by default we create the model on the default model connection, only if a connection is provided to the methods we'll use it to create our model.

@themsaid

Copy link
Copy Markdown
Member Author

@taylorotwell there's already a way to create models on a different connection as the above example, so feel free to close the PR if you think adding the connection argument adds some complexity to the code.

@taylorotwell taylorotwell merged commit 7ece167 into laravel:5.4 Jan 18, 2017
@taylorotwell

Copy link
Copy Markdown
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants