I would very much appreciate your opinion.
I have an existing Laravel project that I have been working for some time.
At some point, as I became more familiar with DDD, and as I realized that Eloquent (being an Active record) makes it hard to work on complex Domain logic, I decided to refactor it into a more Domain Centric Architecture by separating the Domain layer from the Infrastructure.
What I did initially is creating Plain Old PHP Objects (POPO’s) as my Domain entities and abstracting the Eloquent models inside the Infrastructure layer Repositories.
Thus using Eloquent models only for persistence and managing Domain logic inside the POPO’s.
I also created mappers to map from Domain objects to Eloquent models and back when persisting and retrieving.
Still the process felt like fighting Laravel every step of the way and the solution felt less than optimal, because I had to manage all this mapping.
The biggest issue I encountered though was managing relationships between Domain Entities as POPO’s, especially in regard to Lazy Loading.
But I did succeed isolating the Domain logic from the Eloquent persistence logic.
Then I stumbled upon a better solution for DDD: Doctrine ORM.
I decided to use Doctrine instead of Eloquent in Laravel.
To do that I chose the Laravel Doctrine library.
At the moment I am at the process of converting all the persistence from my proprietary Eloquent mapping to Doctrine and it seems to be going well.
The problem is that it still feel like fighting the Laravel framework.
One big issue that I encountered right now is that I cannot get rid of Eloquent models and must still maintain them because I use Laravel Voyager admin library which relies on Eloquent models.
Even if I get rid of Voyager and find another admin panel that would fit, or build a simple one myself, I am concerned that I will encounter more issues with Laravel and it’s ecosystem (libraries) in the future since they could be relying on Eloquent.
I start to think that maybe a better solution would be just migrating from Laravel to Symfony.
What do you think?
Have you encountered similar issues?
Source: Symfony Questions
Was this helpful?
0 / 0