0
我已經創建了應用服務/服務/ KDataService.php看起來像這樣:Laravel 5.5依賴注入構造方法
class KDataService
{
/** @var string */
private $license;
/** @var string */
private $owner;
/** @var string */
private $accessToken;
public function __construct($owner, $license)
{
$this->owner = $owner;
$this->license = $license;
...
}
...
}
在我的控制器之一,我嘗試注入與依賴注入這個服務模式,但我得到以下錯誤:
Unresolvable dependency resolving [Parameter #0 [ $owner ]] in class App\Services\KDataService
我的控制器:
use App\Services\KDataService;
class DamagePointController extends Controller
{
/** @var KDataService $kDataService */
private $kDataService;
/**
* Instantiate a new controller instance.
*
* @param KDataService $kDataService
*/
public function __construct(KDataService $kDataService)
{
$this->kDataService = $kDataService;
}
...
}
任何人都知道我可以如何傳遞我的$ owner和$ license?
Laravel版本? – FreeLightman
@FreeLightman 5.5,我也會編輯OP – Chris
'$ owner'和'$ licence'類型是什麼? Laravel不知道注入什麼來建立你的'KDataService'。 –