Laravel随机连接到不同的数据库

I have no idea how to google this since I mostly get tutorials about setting up multiple database connections.

At the moment, completely at random, my Laravel application gives me back an error about SQL, that the table could not be found. Laravel connects in this case to an entitely different database for some reason.

I connect in my .env and config/database.php to database1. Suddenly, an SQL error appears reading

Cannot find table `database2`.`table` in field list.

User also gets logged out when this error occurs.

Might be of use if i include that:

  • I sometimes use a custom user provider and sometimes the Laravel user provider. It depends on the subdomain. Error occurs on both configurations.
  • I dynamically add other database connections to the config, but never one to "database2". Database2 is a completely different application.
  • A search through the source code does not find any match with "database2"

Has anyone come across this problem? And if yes, how do I solve this? Thanks in advance!

Have you defined a model to use a different connection maybe?

Following the Laravel docs, this lets you use a different connection for specific models.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
    /**
     * The connection name for the model.
     *
     * @var string
     */
    protected $connection = 'connection-name';
}