alijumaan / laravel-ecommerce

144 stars 72 forks source link

Interfaces #7

Closed jstojiljkovic closed 2 years ago

jstojiljkovic commented 3 years ago

https://github.com/alijumaan/Laravel-Ecommerce/blob/e1db5c387ce4606a375293b490fe203fa60a0176/app/Http/Controllers/Backend/CategoryController.php#L17

Since you decided to use a Repository pattern, you should create interfaces for each repository and then inject them into the controller, also each class that implements that interface should return the same value not eloquent in that way you are not breaking the Repository pattern.

alijumaan commented 3 years ago

I see some developer use interfaces folder and repository folder in a separate folder like: namespace App\Interfaces namespace App\Repositories

And see other user interfaces inside repositories folder like : namespace App\Repositories\Order;

jstojiljkovic commented 3 years ago

It usually depends on you, what I prefer is to have everything separate, a folder for interfaces and a folder for repositories. That way you know where everything is.

Here is my usual structure:

  1. One Eloquent Model class per datable table
  2. One Repository class per Eloquent Model
  3. A Service class that may communicate between multiple Repository classes.