Skip to content

How to make user plugin generates and use tables in an another database #385

Answered by LukeTowers
informas asked this question in Q&A
Discussion options

You must be logged in to vote

UPDATE: This should be fixed as of wintercms/storm@2cd7370

Your provided example is actually pretty close to how you would actually go about doing this, you just need to call setConnection() instead of connection(). See https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Model.html#method_setConnection.

UserModel::extend(function ($model) {
    $model->setConnection('custom-connection');
});

NOTE: You can also run specific queries on a given connection if you want by calling the MyModelClass::on('custom-connection') to get a query builder instance initialized to the provided connection, see https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Model.html#method_on.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@LukeTowers
Comment options

@informas
Comment options

@informas
Comment options

@LukeTowers
Comment options

@informas
Comment options

Answer selected by informas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants