Overthinking in which class to put a method in.

Posted 3 years ago by PavanKataria

Hey, here's some code that I have in my controller which contain methods all connected to my routes. Please see the code pasted into this Laravel paste bin. http://laravel.io/bin/E301B

Each method calls a method from my repository, and then calls a method on a transformer manager class to process the dataset into the final result. (appending the wrapper data around my json, essentially)

I have an OrdersController, which has a Fractal manager, orderRepository and OrderService class all of them instantiated through the constructor.

OrderRepository, contains all my database querying logic

OrderService I was thinking of putting my duplication method here.. there's nothing in here atm. If I move the duplication into a method in this class then that'll mean I'll have to pass a fractal instance to this method too which is ugly, and I could instead instantiate my fractal manager here instead of inside my controller...

Normally the controller is responsible for handling HTTP related stuff, json, and transformations, right? So should I just decouple the duplication in my OrdersController instead?

Any thoughts? Lol. Sorry, normally this kind of stuff doesn't hinder me at all, not sure what's happening today.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.