Core Module
The core module has a base repository and an abstract Eloquent implementation.
Your repositories and its interfaces can extend those base class/interfaces for less code duplication.
All you need to do to bind the interface to the implementation is something like the following:
$this->app->bind(PostRepository::class, function() {
return new EloquentPostRepository(new Post);
});
Instead of passing a string as a second argument to your implementation class, you pass a closure with the implemented class with needs an instance of the model.
If your entity isn't translatable you'll have to overwrite the all
and find($id)
methods on your eloquent repository implementation:
public function find($id)
{
return $this->model->find($id);
}
public function all()
{
return $this->model->orderBy('created_at', 'DESC')->get();
}