4

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メソッドを使用する必要があるのでしょうか?

4

1 に答える 1