1. Go to this page and download the library: Download bmatovu/laravel-xml library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bmatovu / laravel-xml example snippets
$request->xml();
$request->sentXml();
$request->wantsXml();
$isValid = Xml::is_valid($request->xml());
if (! $isValid) {
return response()->xml(['message' => 'The given data was malformed.'], 400);
}
$errors = Xml::validate($request->xml(), 'path_to/sample.xsd');
if ($errors) {
return response()->xml([
'message' => 'The given data was invalid.',
'errors' => $errors,
], 422);
}
Route::get('/users/{user}', function (Request $request, int $userId) {
$user = User::findOrFail($userId);
return response()->xml($user);
});
Route::get('/users/{user}', function (Request $request, int $userId) {
$user = User::findOrFail($userId);
return response()->xml(['user' => $user->toArray()]);
});
Route::get('/users/{user}', function (Request $request, int $userId) {
$user = User::findOrFail($userId);
return response()->xml($user, 200, [], ['root' => 'user']);
});