Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target [] is not instantiable while building #5

Open
ghost opened this issue Jul 27, 2016 · 3 comments
Open

Target [] is not instantiable while building #5

ghost opened this issue Jul 27, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 27, 2016

I'm getting this error message even after following your tutorial. I'm using Laravel 5.2. See my setup:

App\Entities\Usuario.php
`<?php

namespace App\Entities;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;

class Usuario extends Authenticatable
{
use SoftDeletes;
protected $table = 'usuarios';
protected $dates = ['deleted_at'];
protected $fillable = [
'regra', 'nome', 'sobrenome', 'rg', 'emissor', 'cpf', 'nascimento', 'telefone', 'celular',
'skype', 'cep', 'logradouro', 'numero', 'bairro', 'cidade', 'uf', 'email', 'password'
];
protected $hidden = ['password', 'remember_token'];

/* Setter's */

public function setNomeAttribute($value)
{
    $this->attributes['nome'] = trim(ucwords($value));
}

public function setSobrenomeAttribute($value)
{
    $this->attributes['sobrenome'] = trim(ucwords($value));
}

public function setRgAttribute($value)
{
    $this->attributes['rg'] = trim($value);
}

public function setEmissorAttribute($value)
{
    $this->attributes['emissor'] = trim(strtoupper($value));
}

public function setSkypeAttribute($value)
{
    $this->attributes['skype'] = trim(strtolower($value));
}

public function setLogradouroAttribute($value)
{
    $this->attributes['logradouro'] = trim(ucwords($value));
}

public function setNumeroAttribute($value)
{
    $this->attributes['numero'] = trim($value);
}

public function setBairroAttribute($value)
{
    $this->attributes['bairro'] = trim(ucwords($value));
}

public function setCidadeAttribute($value)
{
    $this->attributes['cidade'] = trim(ucwords($value));
}

public function setUfAttribute($value)
{
    $this->attributes['uf'] = trim(strtoupper($value));
}

public function setEmailAttribute($value)
{
    $this->attributes['email'] = trim(strtolower($value));
}

public function setPasswordAttribute($value)
{
    if(!empty($value)){
        $this->attributes['password'] = \Hash::make($value);
    }
}

}`

App\Repositories\Usuarios\UsuariosInterface.php
`<?php

namespace App\Repositories\Usuarios;

use Torann\LaravelRepository\Repositories\RepositoryInterface;

interface UsuariosInterface extends RepositoryInterface
{
//
}`

App\Repositories\Usuarios\UsuariosRepository.php
`<?php

namespace App\Repositories\Usuarios;

use Torann\LaravelRepository\Repositories\AbstractRepository;

class UsuariosRepository extends AbstractRepository implements UsuariosInterface
{
/**
* Specify Model class name
*
* @return string
*/
protected $model = \App\Entities\Usuario::class;
}`

App\Providers\RepositoriesServiceProvider.php
`<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Torann\LaravelRepository\RepositoryFactory;

class RepositoriesServiceProvider extends ServiceProvider
{
public function boot() {}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(
'App\Repositories\Usuarios\UsuariosInterface', function ($app) {
return RepositoryFactory::create('Usuarios');
});
}
}`

App\Http\Controllers\UsuariosController.php
`<?php

namespace App\Http\Controllers;

use App\Repositories\Usuarios\UsuariosInterface;
use App\Repositories\Usuarios\UsuariosRepository;
use Illuminate\Http\Request;
use App\Http\Requests;

class UsuariosController extends Controller
{
protected $repository;

public function __construct(UsuariosInterface $repository)
{
    $this->repository = $repository;
}

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return $this->repository->all();
}

}`

@ghost
Copy link
Author

ghost commented Jul 27, 2016

Error:

BindingResolutionException in Container.php line 748:
Target [App\Repositories\Usuarios\UsuariosInterface] is not instantiable while building [App\Http\Controllers\UsuariosController].

@blogui91
Copy link

@samuelcdossantos , Just add App\Providers\RepositoriesServiceProvider::class in config/app.php, it should work :)

@Torann
Copy link
Owner

Torann commented Nov 10, 2016

Any luck?

Also a little tip, I would move all of your setters to an observer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants