Have you tried the php xml parser: https://www.php.net/manual/en/book.xml.php
Importing and parsing xml response from an API
Hi guys,
I've been going through the basic Laravel course here, and will start the intermediate one this weekend.
I built a site which is essentially a blog, but with more meta data.
I have a table of my data, i.e. featured image, body, heading etc. and another table with a model for imported data.
This data will never be manually changed, but will be pulled from an XML api that I have access to (I'm allowed to use this data, it's a private API). This data is numerical and boolean mainly, i.e. financial data. It will serve as additional data/meta data for my blog posts.
I already wrote a php script to pull this data for test, but I would like to incorporate this into Laravel.
What would be the best setup for this?
I would like to poll the api let's say weekly/monthly (it doesn't change often), and overwrite records and import new ones. Then when I make a post, I will manually link them with Eloquent relationships to my posts.
I imagine a job/schedule will be the way to go here? But would I do the xml parsing in my controller? What's the best practice here? As a start, I can have it as a manual method, where I can trigger it from a route as an authenticated user, if that's easier, then work it into a job/schedule later.
Basically all it will do is grab the xml, make it into an array and then write to the db via the model.
I have it running in Wordpress now, but as I'm rebuilding the site, I would like to make it my first real world Laravel project. Has anyone made something similar with REST or XML APIs earlier, and can give me some best practices?
Thanks in advance
Laravel Noob, Spain
Please or to participate in this conversation.