Support the ongoing development of Laravel.io →
Configuration Database Eloquent
Last updated 2 years ago.
0

thanks for the solution @astroanu I was still hoping for someone to explain how the model connection gets resolved at runtime though.

0

Hi. You can simply extend the used base Model class with a new one, and have the following inside it:

/**
* @return string
*/
public function getConnectionName()
{
    $databaseConnection = config($this->getConfigFileName().'.database_connection');
    if (!empty($databaseConnection)) {
       $this->connection = $databaseConnection;
    }
    return parent::getConnectionName();        
 }

Then you simply produce a function called 'getConfigFileName()'. This way you specify connection name for any implementations of this new Model extension class dynamically using config file(s).

Hope this helps.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

parn09 parn09 Joined 21 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.