PHP code example of tomschlick / request-migrations
1. Go to this page and download the library: Download tomschlick/request-migrations 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/ */
class GroupNameMigration extends RequestMigration
{
/**
* Migrate the request for the application to "read".
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Request
*/
public function migrateRequest(Request $request) : Request
{
return $request;
}
/**
* Migrate the response to display to the client.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function migrateResponse(Response $response) : Response
{
$content = json_decode($response->getContent(), true);
$content['firstname'] = array_get($content, 'name.firstname');
$content['lastname'] = array_get($content, 'name.lastname');
unset($content['name']);
return $response->setContent(json_encode($content));
}
/**
* Define which named paths should this migration modify.
*
* @return array
*/
public function paths() : array
{
return [
'users/show',
];
}
}
use TomSchlick\RequestMigrations\Facades\RequestMigrations;
// set both response & request versions
RequestMigrations::setVersion('2017-01-01')
// set the request version
RequestMigrations::setRequestVersion('2017-01-01')
// set the response version
RequestMigrations::setResponseVersion('2017-01-01')