I am trying to bind interface to implementation. I have created an interface in app\Contracts\Services\LoginServiceContract.php
namespace App\Contracts\Services;
interface LoginServiceContract{
...
}
Service in app\Services\LoginService.php
namespace App\Services;
use App\Contracts\Services\LoginServiceContract;
class LoginService extends Service implements LoginServiceContract{
...
}
LoginService extends Service class which is also in same namespace as LoginService.
I have bind the LoginServiceContract to LoginService in AppServiceProvider.php in register method as below:
public function register()
{
$this->app->bind( 'App\Contracts\Services\LoginServiceContract', 'App\Services\LoginService' );
}
And LoginController.php contains:
namespace App\Http\Controllers\API\V1;
use App\Contracts\Services\LoginServiceContract;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class LoginController extends Controller{
private $loginService;
public function __construct( LoginServiceContract $loginService ){
$this->loginService = $loginService;
}
public function index( Request $request ){
$this->loginService->session( $request );
}
}
When I make a request to LoginController@index, following error occurs:
BindingResolutionException in Container.php line 873:
Target [App\Contracts\Services\LoginServiceContract] is not instantiable while building [App\Http\Controllers\API\V1\LoginController].
I have tried following commands in terminal:
- php artisan clear-compiled
- php artisan cache:clear
- composer dump-autoload
Am I missing anything here?
via user3810785