2015-02-18 13 views
14

Dostaję taki błąd:Cel nie jest dostępny. Laravel 5 - App wiązanie z operatorem

BindingResolutionException in compiled.php line 1029: 

Target [App\Models\Contracts\Repositories\IUserRepository] is not instantiable. 

Mój kod wygląda następująco:

Interfejs:

namespace App\Models\Contracts\Repositories; 

use App\Models\Objects\DTO\User; 

interface IUserRepository 
{ 
    function Create(User $user); 
} 

Beton:

namespace App\Models\Concrete\Eloquent; 

use App\Models\Contracts\Repositories\IUserRepository; 
use App\Models\Objects\DTO\User; 

class EqUserRepository implements IUserRepository 
{ 
    /** 
    * Create a new user instance after a valid registration. 
    * 
    * @param array $data 
    * @return User 
    */ 
    public function Create(User $user) 
    { 
     return User::create([ 
        'first_name' => $user->first_name, 
        'last_name' => $user->last_name, 
        'username' => $user->username, 
        'email' => $user->email, 
        'password' => bcrypt($user->password), 
       ]); 
    } 

} 

Service Provider:

<?php namespace App\Providers; 

use Illuminate\Support\ServiceProvider; 

class AppServiceProvider extends ServiceProvider { 

    /** 
    * Bootstrap any application services. 
    * 
    * @return void 
    */ 
    public function boot() 
    { 
     // 
    } 

    /** 
    * Register any application services. 
    * 
    * This service provider is a great spot to register your various container 
    * bindings with the application. As you can see, we are registering our 
    * "Registrar" implementation here. You can add your own bindings too! 
    * 
    * @return void 
    */ 
    public function register() 
    { 

      $this->app->bind(
        'App\Models\Contracts\Repositories\IUserRepository', 
        'App\Models\Concrete\Eloquent\EqUserRepository' 
      ); 
    } 

} 

Kontroler:

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Contracts\Auth\Guard; 
use Illuminate\Contracts\Auth\Registrar; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 

use App\Models\Contracts\Repositories\IUserRepository; 
use App\Models\Objects\DTO\User; 

class AuthController extends Controller 
{ 
    protected $auth; 
    private $userRepository; 

    public function __Construct( 
      Guard $auth, 
      IUserRepository $userRepo) 
    { 
    ... 

Struktura folderów

enter image description here

widziałem też, że może muszę deklarować nazw w moim composer.json, Tak próbowałem następujące, jak również tylko powyższe:

"autoload": { 
     "classmap": [ 
      "database" 
     ], 
     "psr-4": { 
      "App\\": "app/", 
      "App\\Models\\Concrete\\Eloquent\\": "app/Models/Concrete/Eloquent/", 
      "App\\Models\\Contracts\\Repositories\\": "app/Models/Contracts/Repositories/", 
      "App\\Models\\Objects\\DTO\\": "app/Models/Objects/DTO/" 
     } 
    }, 

a następnie pobiegł composer dump-autoload

Jakieś pomysły co ja zapominając zrobić?

+0

Przeniosłem konkretne repozytorium do folderu usług i nadałem mu ten obszar nazw. Wciąż ten sam błąd. – Jimmyt1988

Odpowiedz

16

Zauważyłem, że plik compiled.php nie był aktualizowany.

Uruchom tę funkcję w cmd linii w folderze głównym projektu:

php artisan clear-compiled 
+0

To było bardzo pomocne –

+0

Musiałem uruchomić kilka innych poleceń, aby wyczyścić pamięć podręczną i zoptymalizować również. 'php rzemieślnik config: wyczyść' 'php rzemieślnik jasny skompilowany' 'php rzemieślnik zoptymalizuj' ' php rzemieślnik config: cache' –

5

Jeśli również uruchomić w poniżej błędu:

BindingResolutionException in Container.php line 749: Target [App\Contracts\TestContract] is not instantiable.

Wyczyść pamięć podręczną config z:

php artisan config:clear 
+0

Wygląda na to, że możesz mi pomóc. Spójrz na to: https://laracasts.com/discuss/channels/laravel/how-can-i-solve-target-apprepositoriesnewsreposi –