Thanks for this article @davidrjenni
, very informative and well-written.
One thing I believe is missing is the whole point of having repositories; to abstract entity management from storage layer. One is able to substitute the storage layer at will. This is immensely helpful when you sync data accross several API, here's an example:
<?phpinterfaceOrderEntity{publicfunctiongetUuid():?string;publicfunctiongetAmount():int;}classOrderextendsModelimplementsOrderEntity{// ...}interfaceOrderRepository{publicfunctionhas(OrderEntity$order):bool;publicfunctionfind(string$uuid):OrderEntity;publicfunctionsave(OrderEntity$order):void;}classOrderDatabaseRepositoryimplementsOrderRepository{// Saves the order on the database using Eloquent}classOrderStripeRepositoryimplementsOrderRepository{// Sends the order to Stipe using its API}classOrderHubspotRepositoryimplementsOrderRepository{// Stores a copy of the order on Hubspot for the sales dept}
If the API you're talking to is REST compliant, implementing a repository that talks to it is a breeze (no state to manage.)
There are many other reasons why you would want to use repositories with Laravel. Especially if you're designing with DDD. You can read more about that on my dev.to page 😉
Thank you, @bdelespierre
for your feedback, much appreciated 🙏.
One thing I believe is missing is the whole point of having repositories; to abstract entity management from storage layer.
I'll expand on the reasons I think the Repository pattern is helpful in the next blog post. I wanted to keep this post focused on the general concept and how to implement it in Laravel.
You can read more about that on my dev.to page 😉
I'll definitively check them out 👍. Thanks for the pointer.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for this article @davidrjenni , very informative and well-written.
One thing I believe is missing is the whole point of having repositories; to abstract entity management from storage layer. One is able to substitute the storage layer at will. This is immensely helpful when you sync data accross several API, here's an example:
Moving data around becomes as easy as:
If the API you're talking to is REST compliant, implementing a repository that talks to it is a breeze (no state to manage.)
There are many other reasons why you would want to use repositories with Laravel. Especially if you're designing with DDD. You can read more about that on my dev.to page 😉
Thank you, @bdelespierre for your feedback, much appreciated 🙏.
I'll expand on the reasons I think the Repository pattern is helpful in the next blog post. I wanted to keep this post focused on the general concept and how to implement it in Laravel.
I'll definitively check them out 👍. Thanks for the pointer.