DEV Community

Discussion on: Auto-generated Repository Pattern in Laravel

Collapse
 
bdelespierre profile image
Benjamin Delespierre

Great article! Would it be at all possible to see how to use the repositories in controllers?

Collapse
 
ngodinhcuong profile image
Ngo Dinh Cuong

Thank you for your question :)
Yes, you can use repositories by manually adding them

    public function __construct(UserInterface $userInterface, StaffInterface $staffInterface, ProductInterface $productInterface)
    {
        $this->userInterface = $userInterface;
        $this->staffInterface= $staffInterface;
        $this->productInterface= $productInterface;
    }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bdelespierre profile image
Benjamin Delespierre

Is the UserInterface an entity? A Repository? Also, why would you suffix a property name with interface when it's an object?

Thread Thread
 
ngodinhcuong profile image
Ngo Dinh Cuong

Thank you :)!
Laravel allows you binding Interfaces To Implementations. This means lara-repository already do it for you.
\App\Repositories\Staff\StaffInterface::class => \App\Repositories\Staff\StaffRepository::class,
lara-repository injects the StaffRepository when a class needs an implementation of StaffInterface.