Up
What is the advantage from fetching directly from the DB or fetching from the DB via an api ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm learning Laravel. What I would like to know if fetching data from my database for feeding a map (leaflet JS)
Let's say, I have a table called Location which contains all the location (id, name, latitude, longitude).
So far, what I want to do is the following:
But I saw that there is another way to do it using axio i.e fetch data from API. For example axios.get('{{ route('api.location.index') }}') For example the url /api/locations would returns a json that contains all my locations data. So this time, my LocationController will be a ressource and I will have a Location API in my API Folder.
What is the recommended way to do things ? Is doing API for fetching data is a better practice ?
Please or to participate in this conversation.