The Repository Pattern and Dependency Injection — 30 Days of Laravel: Day 13

preview_player
Показать описание

👨‍💻 Learn Test-Driven Development with Laravel!

👨‍💻 Sign up to my newsletter and receive PHP, JS and Laravel news in a weekly-basis:

🎉 Party up:

Thanks for watching!
Рекомендации по теме
Комментарии
Автор

The whole point is that you get to abstract away where and how the data is stored. That's why it's a Repository, not a Service etc. I'm using Repositories in Laravel to pull in data from CSVs, APIs, MS-SQL, and MySQL, and the code to read and write that data is identical, regardless of the source / storage and retrieval mechanism. I can iterate over different repositories, calling the same methods on each of them, for example. In a sense, the Interface of the Repository is the most important part; the key abstraction layer.

lo_fye
Автор

You should inject an Interface on Controllers instead Repository class, because the Interface can be implemented by real repository or a fake repository to be tested, your way you are binding the Repository class to Controller.

paulocardoso
Автор

Hey man, what’s Php storm font are you using in this video?

wribeiro
Автор

04:38 `newEloquentBuilder` exists to solve that problem without introducing repositories. 95% of apps don't need the added complexity that come from repositories. Also, there is no way of swapping implementations as you did not bind an implementation to an abstraction. Repository methods should never return Eloquent models.

This one was a mixed bag to be frank.

mabdullahsari