[求助] [Laravel 5.2] 如何利用Laravel driver访问多个不在app\config\database.php里得sqlite3数据库

有多个sqlite数据库源文件,没有放在app\\config\\database.php中管理,但是自己想使用Laravel的数据库driver来操作这些数据,有什么办法在操作数据库前,更改connections->'sqlite'->'database'的值呢?

'connections' => [

        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => database_path('database.sqlite'), <== 我想更换的数据源文件
            'prefix'   => '',
        ],

        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'engine'    => null,
        ],
    ],<br></br>

之前也Google到了两个帮助信息,不过都是如何切换在database.php中已经配置了的数据库的,在我需求中,把所有sqlite数据库都放在database.php中不太现实。

http://fideloper.com/laravel-multiple-database-connections| 999093570d9b83cad9beb4e810f7b57e1 |

http://stackoverflow.com/questions/31847054/how-to-use-multiple-database-in-laravel| 999093570d9b83cad9beb4e810f7b57e3 |

非常感谢!!!

    // eloquent class.
    // add dynamic sqlite database setting.
    protected static $sqliteDatabase = 'yourname';

    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        // We do config here.
        if ($sqlite = static::$sqliteDatabase) {
            app()['config']->set('database.connections.sqlite.database', $sqlite);
        }
    }
Tomoe
修改的评论也不能少于六个字哦!
justtest
修改的评论也不能少于六个字哦!
sunnirvana
修改的评论也不能少于六个字哦!
JellyBool
修改的评论也不能少于六个字哦!
justtest
修改的评论也不能少于六个字哦!
sunnirvana
修改的评论也不能少于六个字哦!
sunnirvana
修改的评论也不能少于六个字哦!