Package Data | |
---|---|
Maintainer Username: | tucker-eric |
Maintainer Contact: | tucker.ericm@gmail.com (Eric Tucker) |
Package Create Date: | 2016-12-01 |
Package Last Update: | 2024-03-03 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 03:01:06 |
Package Statistics | |
---|---|
Total Downloads: | 1,171,048 |
Monthly Downloads: | 515 |
Daily Downloads: | 1 |
Total Stars: | 18 |
Total Watchers: | 4 |
Total Forks: | 10 |
Total Open Issues: | 2 |
A Laravel Middleware to accept XML requests
composer require tucker-eric/laravel-xml-middleware
In config/app.php
add the service provider to the providers array:
'providers' => [
//Other Service Providers
XmlMiddleware\XmlRequestServiceProvider::class,
];
In app/Http/Kernel.php
protected $routeMiddleware = [
/// Other Middleware
'xml' => \XmlMiddleware\XmlRequestMiddleware::class,
];
Add the middleware to your route as desired
class MyController extends Controller
{
public function __construct()
{
$this->middleware('xml');
}
}
Route::group(['middleware' => 'xml'], function() {
Route::post('my-api-endpoint', 'MyOtherController@store');
});
Route::post('my-api-endpoint', 'MyOtherController@store')->middleware('xml');
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();
}
}
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);
}
}