Stormhammer Stormhammer - 1 year ago 65
PHP Question

Where to have the communication with API and calculations in Laravel 5

I'm still very much in the planningprocess of a new, large project. Since this is quite a big project we decided to use Laravel 5. However, alot of the data is obtained through an API. Currently, this is a done through a model, but I was wondering if there's a better way to do this.

Also, there's alot of mathematical calculations that will be used through-out the project. Most calculations will be used in multiple controllers, but I don't feel like these belong in any model. What would be a good place to put these, so that they can be used by controllers.

Answer Source

I think for calculations you need create folder like "Services", and put all files for different calculations in this folder and use those in controllers.

For API you can use "Services" too and put all code for auth, getting some data etc. to different classes, it'll easy to use when you need.

So you'll have smth like this:




This is one of the variants.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download