https://github.com/tucker-eric/laravel-xml-middleware
A Laravel Middleware to accept XML requests
https://github.com/tucker-eric/laravel-xml-middleware
laravel laravel-middleware laravel-xml xml xml-request
Last synced: about 2 months ago
JSON representation
A Laravel Middleware to accept XML requests
- Host: GitHub
- URL: https://github.com/tucker-eric/laravel-xml-middleware
- Owner: Tucker-Eric
- License: mit
- Created: 2016-12-01T06:17:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-03T02:07:16.000Z (over 1 year ago)
- Last Synced: 2025-04-09T11:19:04.317Z (about 2 months ago)
- Topics: laravel, laravel-middleware, laravel-xml, xml, xml-request
- Language: PHP
- Size: 18.6 KB
- Stars: 18
- Watchers: 3
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# laravel-xml-middleware
[](https://packagist.org/packages/tucker-eric/laravel-xml-middleware)
[](https://packagist.org/packages/tucker-eric/laravel-xml-middleware)
[](https://packagist.org/packages/tucker-eric/laravel-xml-middleware)
[](https://travis-ci.org/Tucker-Eric/laravel-xml-middleware)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:```php
'providers' => [
//Other Service Providers
XmlMiddleware\XmlRequestServiceProvider::class,
];
```### Register the middleware
In `app/Http/Kernel.php````php
protected $routeMiddleware = [
/// Other Middleware
'xml' => \XmlMiddleware\XmlRequestMiddleware::class,
];
```### Applying the middleware to routes
Add the middleware to your route as desired#### Controller Middleware
```php
class MyController extends Controller
{
public function __construct()
{
$this->middleware('xml');
}
}
```#### Route Middleware
```php
Route::group(['middleware' => 'xml'], function() {
Route::post('my-api-endpoint', 'MyOtherController@store');
});
```
```php
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()`:```php
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`:```php
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:
```php
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;Class MyOtherController extends Controller
{
public function store(Request $request)
{
$xml = $request->xml(false);
}
}
```