- How do I install bmatovu/laravel-xml in a Laravel application?
- Install it with composer require bmatovu/laravel-xml. The service provider is registered through Laravel package auto-discovery, so no manual provider entry is usually needed. Publish the config file with php artisan vendor:publish and then add your first XML route. Before pinning, read the composer.json illuminate/support constraint to confirm it covers your Laravel major.
- Which Laravel and PHP versions does laravel-xml support?
- Check the illuminate/support constraint and the PHP requirement in the package composer.json; the package targets modern Laravel releases on PHP 8.x. The important unknown is how quickly it tracks new Laravel majors, because a package that lags a major version becomes a release blocker. Confirm tags, green CI, and recent commit history before committing to it.
- How do I return an XML response from a Laravel controller with this package?
- The package exposes response helpers and macros so you can return XML directly from a route or controller, for example by passing an array to the XML response macro. Keep those call sites behind a small responder or presenter class instead of scattering inline response to XML calls through controllers. That keeps the vendor surface to two or three places and makes it trivial to swap serializers later.
- Can laravel-xml convert an Eloquent model to XML?
- Yes, the workflow is to serialize the model to an array and then convert that array to XML. Do not pass a full toArray() result, because that exposes every column and couples responses to the database schema. Use explicit field allow-lists with only() or a dedicated resource array, and be deliberate about relations, dates, and hidden attributes.
- Does laravel-xml handle XML namespaces, attributes, CDATA, and XSD validation?
- It is a generic array-to-XML serializer, so it handles the XML envelope but not a partner-specific schema contract. Attributes versus elements, namespace declarations, CDATA sections, and element ordering generally cannot be expressed by a plain array without extra care. XSD validation is out of scope, so if a partner enforces a schema you need schema-aware generation and validation on your side.
- Does laravel-xml support Accept header content negotiation, or only explicit XML routes?
- Prefer explicit XML routes and let JSON routes stay JSON; that is the predictable design and avoids surprising API clients. Content negotiation adds complexity and is best confirmed in the source before you rely on it. If you do need negotiation, test it yourself against real Accept headers rather than assuming it works.
- Is laravel-xml a good fit for sitemaps and RSS or Atom feeds?
- Yes, feed and sitemap generation is one of the strongest use cases because those documents are simple, schema-stable, and rarely need attributes or namespaces beyond the standard set. Build the items as an array and return them through the XML response helper. For very large sitemaps, stream the output instead of building the whole document in memory, and verify the Content-Type header your clients receive.
- How should I test XML responses from a Laravel API built with this package?
- Use DOM-based assertions rather than string comparison, otherwise whitespace and attribute ordering changes will make the suite brittle and developers will start skipping it. Laravel's assertXmlStringEqualsXmlString or a SimpleXMLElement comparison against a fixture works well. Also assert the Content-Type header, and add contract tests against real partner payloads or an XSD when a schema is involved.
- Is laravel-xml safe, and does it parse inbound XML (XXE risk)?
- The package is focused on emitting XML, so if it only serializes output the XXE attack surface largely disappears. If you accept inbound XML anywhere in your stack, harden the parser by disabling external entity loading and avoiding flags like LIBXML_NOENT. Also verify entity escaping and the charset and Content-Type headers, and never auto-serialize whole models into responses.
- What are the alternatives to laravel-xml, and is it worth adopting in production?
- The main alternative is adopting an array-to-XML library such as spatie/array-to-xml directly, or writing a thin internal responder if your needs are narrow. bmatovu/laravel-xml is a small, readable wrapper with a genuine but narrow use case for legacy B2B partner endpoints and feeds. Weigh the technical risk accordingly: the code is low risk, but 88 stars, zero dependents, and a single maintainer mean bus factor 1, so assume you may inherit maintenance and plan to wrap it behind your own interface.