我正在Laravel中开发自定义软件包,我需要用户能够根据配置为软件包模型设置连接。
我做不到:
protected $connection = Config::get('billing.connection');
因为不允许将表达式用作字段默认值。
这样做
public function getConnection()
{
return Config::get('billing.connection'); // TODO: Change the autogenerated stub
}
上面写着Call to a member function getQueryGrammar() on a string.
,我是否可以通过其他方法允许用户为我的软件包模型设置数据库连接?
答案 0 :(得分:0)
您应该为此覆盖其他方法。代替
public function getConnection()
{
return Config::get('billing.connection'); // TODO: Change the autogenerated stub
}
您应该使用
public function getConnectionName()
{
return Config::get('billing.connection'); // TODO: Change the autogenerated stub
}