An interface only states that a class has implemented whatever methods are defined in the interface. Because EloquentItem extends Eloquent, anything in Eloquent is available to any instance of EloquentItem.
If you are truly trying to do a repository, then you need to make the repository not extend EloquentItem.
interface ItemReposistory
{
public function find($id);
}
class ItemServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('ItemRepository', 'ItemRepositoryEloquent');
}
}
class Item extends Eloquent
{
}
class ItemRepositoryEloquent implements ItemRepository
{
protected $item;
public function __construct(Item $item)
{
$this->item = $item;
}
public function find($id)
{
return $this->item->find($id);
}
}
class ItemController extends BaseController
{
protected $item;
public function __construct(ItemRepository $item)
{
$this->item = $item;
}
}
Ah, thanks for the explanation! That's how I originally had it set up after following a tutorial, but was hoping I could save a step and wrap Item into ItemRepositoryEloquent to simplify things :\
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community