How to make user plugin generates and use tables in an another database #385
-
It may be possible to do, and with a few simple modifications to the plugin, that instead of using the default database, it uses its associated tables but in an another external auxiliary database? By the term "simple", I mean something, for example similar to the following hypothetical code: Plugin.php file use System\Classes\PluginBase;
use Winter\User\Models\User as UserModel;
class Plugin extends PluginBase;
{
public function boot()
{
UserModel::extend(function ($model) {
$model->connection('second_database');
});
}
} And as a consequence of this "adjustment" any use of this model, always works on that second database. Please note that, the idea behind this post is to use the same methodology for other plugins, not only User plugin. The objective would be to separate a certain part of the data (enterprise model data) from the more specific design data of the site. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
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 UserModel::extend(function ($model) {
$model->setConnection('custom-connection');
});
|
Beta Was this translation helpful? Give feedback.
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 ofconnection()
. See https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Model.html#method_setConnection.