fero's avatar
Level 12

Large scale laravel app structure ambiguity

Hi all,

I'm trying to create a new app using laravel (5.6) as a framework and i'm having some trouble figuring out the structure should be.

The first problem I ran into is where you put most of the logic. I know there's been a lot of questions about this topic but i couldn't find an answer reading the forums. To be more precise, what I'm trying to do is save a user to the database. The user, when creating an account has the option to add an avatar image but it's not required to do so. If the user doesn't upload an avatar image, I'm creating one for him.

For this, in the controller I accept a FormRequest class as the param, witch validates the input, and then i call a repository->create() method.

Now, the repository should only be concerned with DB operations so the mothod for creating an avatar image for him should not be in the repository and I don;t know where to put it. I come from a symfony background where, from a controller you would call a service, with in turn would call a repository to store the data. In this service you could have more logic, even creating the avatar image for him.

In laravel though, I noticed there's no services so what do I have to do in order to achieve a clean design ? Would EventListeners be an option ? Creating and saving an image should be the model's/repository's responsability ?

Maybe I'm missing something about laravel app structure but the thing is I just started working with it and I didn't have the time to read all the docs (although I searched for this question a lot).

Some advice about this will be highly appreciated. Thanks

0 likes
3 replies
fero's avatar
Level 12

@topvillas yeah I know I tend to overthink things like this but the production code usualy goes throug a pretty rigourous code review and while it's sort of subjective, it comes close to SOLID.

But even though my colleagues b***h about it, they don't offer much of a solution, just stuff like "breaks single responsibility...". or "you didn't use interfaces". Anyways, I know this topic is kind of opinionated and some will say SOLID is the way to go and most will recommend to KISS but honestly, I'm just trying to get the darn thing done with the least pain in CR. I don't intend to follow all the practices, just what makes sense to me.

Just create a simple class that handles avatar creation. Don't overthink it.

Yup, planning on it, currently it's still in the repository, but I'm courious who should call it. The repository, the controller, the model, the event handler ? For the sake of Keeping It Stupidly Simple, I'll just call it from the repository until I find a better place for it (maybe never).

About Lucid, the first time I use a framework I want to use the original, not a fork because of the support I find. Laravel has plenty of support and @JeffreyWay is also an awesome presenter. But it look good. I never heard of lucid-architecture untill now and I feel comfortable with it, I'll give it a try on a side project.

martinbean's avatar

I just started working with [Laravel] and I didn't have the time to read all the docs

@fero I’d suggest reading the docs. It’ll answer many of the questions you’ll have.

You can’t expect to create a “large scale” application in a framework you’ve not taken the time to research.

Please or to participate in this conversation.