【发布时间】:2018-10-26 13:48:17
【问题描述】:
我观看了一个 laravel 视频课程,其中在 web.php 中演示了服务容器的使用(仅作为示例),在 web.php 中它可以正常工作:
interface KekInterface {};
class Kek implements KekInterface {};
app()->bind('KekInterface', function() {
return new Kek;
});
Route::get('/', function(KekInterface $kekat) {
dd($kekat);
});
我决定将我所有的代码移动到一个控制器(控制器类):
public function index(KekInterface $api)
{
dd($api);
}
接口和类:
interface KekInterface {};
class Kek implements KekInterface {};
app()->bind('KekInterface', function() {
return new Kek;
});
然后 laravel 叫了一声:
目标 [App\Http\Controllers\KekInterface] 不可实例化。
我不知道是什么导致了问题,但我猜这只是命名空间
【问题讨论】: