It depends on how often the data changes. if it is relatively static (e.g. store locations), then writing an XML file to the filesystem would be fine. Otherwise, you probably need to generate the XML dynamically (probably with an appropriate cache length) and output it directly in your response.
Either way, there is nothing wrong with using "plain" PHP and its built-in XML tools to generate your XML data from Eloquent collections.
Thanks, you're right. There is nothing wrong with using plain PHP. Ive found that using PHP's XmlWriter module for building static xml files from eloquent models is super fast and works great.
Also for making future entires into the xml file i now use PHP's built in SimpleXml module to insert new elements as I update my database.
For those of you who may want to implement the static version...
$projects = Project::all();
$xml = new \XMLWriter();
$xml->openMemory();
$xml->setIndent(true);
// Start a new document
$xml->startDocument();
// Start a element to put data in
$xml->startElement('projects');
// Data what goes in your element\
foreach ($projects as $project) {
$xml->startElement('project');
$xml->writeAttribute('id', $project->id);
$xml->writeAttribute('name', $project->name);
$xml->writeAttribute('address', $project->address);
$xml->writeAttribute('lat', $project->lat);
$xml->writeAttribute('lng', $project->lng);
$xml->writeAttribute('type', $project->type);
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
// You put the XML content in this variable
$contents = $xml->outputMemory();
// Reset XML just in case
$xml = null;
Storage::put('projects.xml',$contents);