Coder Social home page Coder Social logo

laravel-xml-middleware's Introduction

laravel-xml-middleware

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);
    }
}

laravel-xml-middleware's People

Contributors

tucker-eric avatar samuelhowell avatar georgeboot avatar adewagold avatar andrewmclagan avatar austinkregel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.