How can I solve Target [App\Repositories\NewsRepository] is not instantiable while building [App\Http\Controllers\Member\NewsController].?

风流意气都作罢 提交于 2019-12-11 17:42:03

问题


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?

来源:https://stackoverflow.com/questions/45956810/how-can-i-solve-target-app-repositories-newsrepository-is-not-instantiable-whi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!