Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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;
    }
}
Last updated 2 years ago.
0

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 :\

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nomstar nomstar Joined 22 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.