How can I solve Target [App\\Repositories\\NewsRep

2019-08-24 12:27发布

问题:

My controller like this :

...
use App\Repositories\NewsRepository;
class NewsController extends Controller
{
    protected $repository;
    public function __construct(NewsRepository $repository)
    {
        $this->repository = $repository;
    }
    public function store(NewsCreateRequest $request)
    {
        ...
        $news = $this->repository->create($input);
        ...
    }
}

My interface like this :

namespace App\Repositories;
use Prettus\Repository\Contracts\RepositoryInterface;
interface NewsRepository extends RepositoryInterface
{
    //
}

My class like this :

...
use App\Repositories\NewsRepository;
class NewsRepositoryEloquent extends BaseRepository implements NewsRepository
{
    public function model()
    {
        return News::class;
    }
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }
}

My repository service provider like this :

...
class RepositoryServiceProvider extends ServiceProvider
{
    ...
    public function register()
    {
        ...
        $this->app->bind(\App\Repositories\NewsRepository::class, \App\Repositories\NewsRepositoryEloquent::class);
    }
}

If the method store on the controller executed, there exist error :

(1/1) BindingResolutionException Target [App\Repositories\NewsRepository] is not instantiable while building [App\Http\Controllers\Member\NewsRepository].

How can I solve the error?