Hello, before I start I must say my english isn't at very high level, so some of you may misunderstand my post, but I hope it will be readable :). My adventure with laravel started about 2-3 months ago, at the beginning I use documentation, but now Laravel API is my bible. I'm pretty good with php (about 4 years of experience), I understand MVC pattern, but last time i tried to make an app i got some problems - my code was a big mess. I would call it 'spaghetti code'. Anyway after deleting old project I started coding again, but still, my code wasn't perfect. I read about service pattern, entities and repository. I tried to implement them into laravel. It wasn't hard, but I'm still thinking that I'm misunderstanding whole MVC pattern. I know that pattern is just set of ideas, not rules, so every programmer can adjust these ideas to code. Anyway in my mind I have this schema: -Controller - controls flow between input, output. Often between http request and output page. Controller uses service for handling actions, so they can remain small. -Model - represents and loads data, in my opinion model should be isolated, each method should affect exactly this instance (except ORM). -View - creates output with data from models -Repository - Abstract layer between data source and entity. Provides basic CRUD methods for entities and relation. There are many repositories, so we can load data from eloquent, xml files, json or sql. -Enitity - is just set of attributes and methods for one thing (for example each user is one entity instance). Entity doesn't loads data itself. Data is provided by repository, so we can access data from various data sources. It's just something like isolate model without data loading. -Service - intermediates between models, handles advanced actions, handles validation, security. Whole 'between logic' is here. By separating application logic into repository, entity and service we can use many many data sources. But service in this way is just singleton (only one instance of each service is needed). We can easily test services / repositories / entities. What do you think? Am I wrong? Or would you change something? What's your way to create apps? I'm Waiting for opinions.
I don't quite agree with your understanding of "repository". Imho it should NOT have application logic and also it is not in between something => it just adds another layer of abstraction to the data source.
Everything else is like I do it: I have a Business/Domain Object which uses Services to check/modify Repositories.
Langdi said:
I don't quite agree with your understanding of "repository". Imho it should NOT have application logic and also it is not in between something => it just adds another layer of abstraction to the data source.
Everything else is like I do it: I have a Business/Domain Object which uses Services to check/modify Repositories.
I meant CRUD on data source only, not validation or something.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community