MooseSaid's avatar

What is the best approach for shipping address section in Laravel?

I'm building e-commerce website where i'm not handling the shipping, instead I'm sending the address details to the seller. I'm working on the shipping address form and I want to build one of those cool address forms where you get a list of all countries, once you select one it gives you a list of all cities and so on. I'm using Laravel with Inertia Vue.

My questions are:

1- Which free API is the most trusted to provide the data I need. I found restcountries.com which is nice but It has more information than I will ever need and to get countries names I have to send a request to get ALL countries information which sounds ridiculous.

2- Should I integrate the API from the frontend with Axios or just use Laravel's HTTP and fetch the data from the backend.

What I'm planning to do is to get countries names from an API, once the user select a country the app send another call to fetch cities ..etc

0 likes
5 replies
martinbean's avatar

@moosesaid Use an address autocomplete form instead. Selecting country, then city, is arduous. Especially if the database isn’t up to date or complete.

Let a user start typing an address and a service offer suggestions as they’re typing.

1 like
MooseSaid's avatar

@martinbean The problem with this approach is most probably for countries like Egypt and many other, address autocomplete doesn't always get you the correct result.

martinbean's avatar

@MooseSaid And neither will some incomplete cities database. Which is why you have text inputs to let the user complete or update any suggested address.

1 like
kokoshneta's avatar
Level 27

I want to build one of those cool address forms where you get a list of all countries, once you select one it gives you a list of all cities and so on

Those aren’t cool. They’re horrible. There are so many addresses that just fail entirely on those forms, leaving the customer with no way of inputting their address at all. Don’t use them.

Addresses are complicated. Everything you take for granted about addresses will be proven incorrect by some format in some country. Trying to ‘beat the system’ by automating things is a recipe for disaster. The only thing you can reasonably assume about an address is that it will be located in a country (exceptions to this are so rare that ignoring them is a reasonable tradeoff). You’re also generally fairly safe in assuming that it will have at least one more specific identifier (usually city). Everything else, all bets are off.

Just let the customer type in their street (allow empty values), postcode (allow empty values), city (don’t allow empty values) and country (select from list; don’t allow empty values).

1 like

Please or to participate in this conversation.