php - instalar - laravel tutorial
El objetivo no es instanciable. Laravel 5: proveedor de servicios de encuadernaciĆ³n de aplicaciones (2)
Noté que compiled.php no se actualizaba.
Ejecute esta función en la línea de cmd en la carpeta raíz de su proyecto:
php artisan clear-compiled
Me aparece este error:
BindingResolutionException in compiled.php line 1029:
Target [App/Models/Contracts/Repositories/IUserRepository] is not instantiable.
Mi código es el siguiente:
Interfaz:
namespace App/Models/Contracts/Repositories;
use App/Models/Objects/DTO/User;
interface IUserRepository
{
function Create( User $user );
}
Hormigón:
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 ),
] );
}
}
Proveedor de servicio:
<?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''
);
}
}
Controlador:
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 )
{
...
Estructura de la carpeta
También he visto que puedo necesitar declarar los espacios de nombres en mi compositor. JSON, así que he intentado lo siguiente y lo anterior:
"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/"
}
},
y luego ejecutó el composer dump-autoload
¿Alguna idea de lo que me olvido hacer?
Si también se ejecuta en el siguiente error:
BindingResolutionException en Container.php línea 749: Target [App / Contracts / TestContract] no es instanciable.
Borre su caché de configuración con:
php artisan config:clear