laravel 5.3具有数据库或elequent访问权限的自定义配置文件

时间:2016-10-03 12:35:29

标签: php laravel laravel-5.3

我在config文件夹中有一个自定义配置文件。我需要在此文件上运行数据库查询或访问Laravel 5.3 eloquent,以便在运行时加载。例如



$site_name = $_SERVER['HTTP_HOST'];
$siteData = Site::whereSiteUrl($site_name)->first();

//echo "<pre>";
//print_r($siteData);
//echo "</pre>";
//exit;


if($siteData)
{
	//echo $siteData->getOriginal('db_password'); exit;
  $dbhost = $siteData->db_host;
  $dbname = $siteData->db_name;
  $username = $siteData->db_user;
  $password = $siteData->getOriginal('db_password');
  $template = $siteData->site_theme;
}
else
{
	
	
	App::error(function($exception, $code)
	{
		 Log::error($exception);
		 return 'Sorry! Something is wrong with this account!';
		//return Response::view('test.error500', array(), 500);
		
	});
}

 //echo $password; exit;

DB::disconnect('mysql');
DB::disconnect('db_lk_prefix');
DB::disconnect('db_coll_prefix');

Config::set('database.connections.mysql', array(
    'driver'    => 'mysql',
    'host'      => $dbhost,
    'database'  => $dbname,
    'username'  => $username,
    'password'  => $password,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
));	  
Config::set('database.connections.db_lk_prefix', array(
    'driver'    => 'mysql',
    'host'      => $dbhost,
    'database'  => $dbname,
    'username'  => $username,
    'password'  => $password,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => 'lk_',
));	  
Config::set('database.connections.db_coll_prefix', array(
    'driver'    => 'mysql',
    'host'      => $dbhost,
    'database'  => $dbname,
    'username'  => $username,
    'password'  => $password,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => 'coll_',
));	

DB::reconnect('mysql');
DB::reconnect('db_lk_prefix');
DB::reconnect('db_coll_prefix');
&#13;
&#13;
&#13;

但它在5.3中根本不起作用,但在4.2中起作用。它显示Fatal error: Call to a member function connection() on null in

任何人都可以提供适当的例子吗?

0 个答案:

没有答案