Support the ongoing development of Laravel.io →
Architecture Queues Jobs

I am just wondering if there is a Laravel (5.0) best practice for this one. I have it implemented as a single list of if...elseif...elseif...else... statements, but I suspect there may be a better way to handle this.

So, in a queued job to process an order, I need to get the country and country region (state or province) for the delivery address of that order. The address will be "dirty data" from a number of different sources. I have a list of different ways in which I can get those details, including local lookup tables, a postal code lookup, remote address validation APIs etc. I would like to run through these methods until I hit the first one that gets an unambiguous match, then I will update the address to link it to my internal list of countries and country regions. Then the order can be pushed onto the next queue for the next process to take it on.

If none of the techniques finds a definite match on the country and region, then an exception is raised and the order goes onto the failed queue so people can be alerts, and data can be fixed before trying again.

So, the bit I'm unsure about, is how to run through all those potential address lookups. Would it make sense to turn each into a command, then run through them one-by-one until one returns a success? Is there a way to group a bunch of commands together in a given order to do this in a loop, or would I just be calling them up procedurally? Each command would be given the Address model object, and would return either a matching CountryRegion, or nothing.

Or is there no advantage to doing this through commands, instead just using procedural code to run through the whole sequence of address checks until one gets a match?

I hope I've explained that clearly enough!

Edit: events just came to mind, but I think this is more about data processing than handling events, but something along the lines of being able to register an "address checker" in some way to add it to the list of services or commands that can check the address, sort of feels like the right way to go..

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

judgej judgej Joined 4 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.