So I have created an API endpoint (obviously not restful) that generates xml and returns the file path of the files. Its obviously more complicated but that is the gist.

My issues is this. Inside my controller I have all of this code that grabs information from the database (using models / relationships etc) and then generates the xml and I feel like this would be better abstracted out instead of cluttering up the controller.

So what do i do? I could easily put together a helper class that handles this all but everyone keeps telling me I should abstract it out into a Service. I've never done this successfully and I just kind of feel like its over-complicating my situation.

Which would be best practice? Is it a BAD practice to just create a helper class? Anyone have an "option C" suggestion?

1 Answer 1


It is all a bit of semantics.

A service would be a helper class, or in a sense a helper class would be a service.

In terms of Laravel. Creating a service (which is a specific thing) would help code reuse and make testing easier.

It is well worth getting over the hump of learning how to do. The number of services you need tends to grow as do the dependencies which is where the service container comes on very useful.

  • 2
    I just feel sometimes like im over-engineering when i go to create a service provider....(in laravel) May 24, 2016 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.