我会按以下方式进行:
将允许的国家/地区列表放入配置文件中(countries.php
) .
In routes.php
:
// choosing country
$country = '';
if (in_array(Request::segment(1), Config::get('countries'))) {
$country = Request::segment(1);
}
// making route for top level
if ($country != '') {
Route::any( '/', 'MainPage@index');
}
// making routes optionally prefixed by country
Route::group(
array('prefix' => $country,
function () {
// here all routes
});
In database.php
在定义连接的地方,您可以添加其他连接,例如:
'germany' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'germany_connection',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
现在在同一个文件中(尽管您可能应该将其移到其他地方)您可以执行以下操作:
if ($country == 'germany') {
DB::disconnect();
Config::set('database.default','germany');
DB::reconnect();
}
您当然可以在此处添加许多条件,或者如果您已为每个允许的国家/地区定义了连接,您可以简单地执行以下操作:
if ($country != '' ) {
DB::disconnect();
Config::set('database.default', $country);
DB::reconnect();
}
它应该可以工作,但我还没有测试过