承接 tucker-eric/laravel-xml-middleware 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tucker-eric/laravel-xml-middleware

最新稳定版本:1.5.0

Composer 安装命令:

composer require tucker-eric/laravel-xml-middleware

包简介

A Laravel Middleware to accept XML requests

README 文档

README

Latest Stable Version Total Downloads License Build Status

A Laravel Middleware to accept XML requests

Configuration

Install Through Composer

composer require tucker-eric/laravel-xml-middleware

Register The Service Provider

In config/app.php add the service provider to the providers array:

    'providers' => [
        //Other Service Providers
        XmlMiddleware\XmlRequestServiceProvider::class,
    ];

Register the middleware

In app/Http/Kernel.php

    protected $routeMiddleware = [
            /// Other Middleware
            'xml' => \XmlMiddleware\XmlRequestMiddleware::class,
        ];

Applying the middleware to routes

Add the middleware to your route as desired

Controller Middleware

class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('xml');
    }
}

Route Middleware

    Route::group(['middleware' => 'xml'], function() {
        Route::post('my-api-endpoint', 'MyOtherController@store');
    });
        Route::post('my-api-endpoint', 'MyOtherController@store')->middleware('xml');

Accessing XML Input With Middleware

If you are using the middleware it will automatically inject the xml into the request as an array and you you can access the xml data in your controller with the $request->all():

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('xml');
    }
    
    public function store(Request $request)
    {
        $request->all();
    }
}

Accessing XML Input

To access the xml input without the middleware use the xml() method on the Request:

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

Class MyOtherController extends Controller
{
    public function store(Request $request)
    {
        $xml = $request->xml();
    }
}

To access the xml request as an object pass false to the xml() method:

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

Class MyOtherController extends Controller
{
    public function store(Request $request)
    {
        $xml = $request->xml(false);
    }
}

统计信息

  • 总下载量: 1.19M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-01