0
我創建了一個名爲Provider
Laravel工廠模式問題
class Provider
{
private $provider;
public function __construct(ProviderInterface $provider)
{
$this->provider = $provider;
}
}
類在工廠類,我有這樣的:
class ProviderFactory
{
public static function adapt(string $provider)
{
switch ($provider) {
case 'ProviderOne':
return app(Provider::class, [app(ProviderOne::class)]);
case 'ProviderTwo':
return app(Provider::class, [app(ProviderTwo::class)]);
}
}
}
當調用ProviderFactory::adapt($request->provider)
我得到一個錯誤:
Target [App\Services\ProviderInterface] is not instantiable while building [App\Services\Provider].
如果我理解正確,我需要bind()
邏輯,因爲它需要知道什麼是雙nd到ProviderInterface
。我需要在服務提供商中添加bind()
邏輯嗎?