kottergroup/laravel-response-xml

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

v3.0.3 2020-05-28 19:05 UTC

README

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

Total Downloads Latest Stable Version Latest Unstable Version

Composer安装

composer require jailtonsc/laravel-response-xml

与Laravel 5.*集成

在config/app.php中添加服务提供者

XmlResponse\XmlResponseServiceProvider::class

在config/app.php中添加别名

'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 许可证