mardi 10 juillet 2018

Laravel 5 How to change a model database connection within controller

My app should connect to an internal and two external commercial SQL databases.

So, I have several models with a connection to an external an MS-SQL database.

The model looks something like that:

class version_Jato extends Model
{
    //
    protected $connection = 'sqlJato';
    protected $table = 'version';
....
}

Until now, everything OK, app works with two databases.

I want to change $connection variable within the controller to let's say

version_Jato-> $connection = 'sqlJato2'.

Is this possible?

Because I have two SQL databases identical as structure only the data is different between them and I don't want to double all the models and the code in the controllers.

Thank you very much for your attention!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KXfiFn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire