lundi 24 juillet 2017

Laravel - Where to implement algorithm functionality

I have the following tables:

Address
id,

long,

latt,

address_1

postcode

Jobs

pickup (links to id in Address)

dropoff (links to id in the Address)

Quotes

pickup (links to id in Address)

dropoff (links to id in the Address)

Part of the functionality is to calculate the distance between the pickup and dropoff but the issue is that I'm currently calculating this functionality inside of the controllers for both the Jobs and of course the Quotes which is not very good because if the functionality changes or whatever, then this requires changing it in both ways. I want to be able to re-use the functionality.

The idea is that, if the pickup and dropoff is changed the Jobs table is changed then this would re-calculate the distance between the two locations. So essentially the Jobs and Quotes will be able to access the function calculateDistance($pickup, $dropoff)

Anyone suggest where I could store this so I'm not repeating and re-using code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire