Eloquent Models
Add the MultipleDatabaseSupport trait to the base Model class (or to individual models if you prefer):
use Alberon\LaravelMultipleDatabases\Models\MultipleDatabaseSupport;
class Model extends Eloquent
{
use MultipleDatabaseSupport;
// ...
}
In each Eloquent model that is not in the default database, set the $table using the format <database>.<table>:
namespace App\Models\Crm;
use App\Models\Model;
class Users extends Model
{
protected $table = 'crm.users';
// ...
}
The database name should match the name used in the configuration, which is not necessarily the real database name.
If you have any BelongsToMany (many-to-many) relationships, add table() around the table name, like this:
public function emailAddresses()
{
return $this->belongsToMany(
EmailAddress::class,
table('crm.email_addresses'), // <-- Here
'user_id',
'email_address_id'
);
}