在我的App\Providers\RouteServiceProvider
我确实创建了方法register
:
public function register()
{
$this->app->bindShared('JustTesting', function($app)
{
die('got here!');
// return new MyClass;
});
}
我应该在哪里使用它?我确实创建了一个方法App\Http\Controllers\HomeController
:
/**
* ReflectionException in RouteDependencyResolverTrait.php line 53:
* Class JustTesting does not exist
*
* @Get("/test")
*/
public function test(\JustTesting $test) {
echo 'Hello';
}
但是没有用,我也不能使用 $this->app->make('JustTesting');
如果我按照下面的代码进行操作,它可以工作,但我想注入控制器。
/**
* "got here!"
*
* @Get("/test")
*/
public function test() {
\App::make('JustTesting');
}
我应该如何像我想要的那样绑定?如果不允许,我为什么要使用该bindShared
方法?