dmsysop/laravel-response-xml

添加将 Laravel 的响应与 xml 集成的功能,将 Eloquent 返回值转换为 XML。

dev-master 2019-05-06 15:14 UTC

This package is not auto-updated.

Last update: 2024-10-01 19:23:30 UTC


README

添加将 Laravel 的响应与 xml 集成的 "xml" 方法,将 Eloquent 返回值转换为 XML。

Total Downloads Latest Stable Version Latest Unstable Version

Composer 安装

composer require jailtonsc/laravel-response-xml

Laravel 5.* 集成

在 config/app.php 中替换 providers

XmlResponse\XmlResponseServiceProvider::class

在 config/app.php 中替换 aliases

'Xml' => XmlResponse\Facades\XmlFacade::class

发布

php artisan vendor:publish

示例

Route::get('/', function () {
    return response()->xml(User::all());
});

带有状态码

Route::get('/', function () {
    return response()->xml(User::all(), 404);
});

通过代码设置

$config = [
        'template' => '<test></test>',
        'rowName' => 'name'
    ];

Route::get('/', function () {
    return response()->xml(User::all(), 200, $config);
});

返回字符串 xml

$xml = Xml::asXml(User::all());

$config = [
        'template' => '<test></test>',
        'rowName' => 'name'
    ];

$xml = Xml::asXml(User::all(), $config);

配置

配置文件 config/xml.php

template: xml 模板。

caseSensitive: XML 标签的大小写敏感。

showEmptyField: 显示空字段。

charset: 编码。

rowName: 如果是数组,则行的名称。

许可证

Laravel Response XML 是开源软件,受 MIT 许可证 授权。