PHP code example of wronx / lumen-rest-object-fetch-middleware
1. Go to this page and download the library: Download wronx/lumen-rest-object-fetch-middleware 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/ */
wronx / lumen-rest-object-fetch-middleware example snippets
$app->routeMiddleware([
// ...
'object' => WRonX\RestObjectFetch\RestObjectFetchMiddleware::class,
]);
$router->group([
'prefix' => '/something/{id:[0-9]+}',
'middleware' => 'object:Something', // <--- HERE
],
function() use ($router) {
$router->get('', [
'as' => 'show_something',
'uses' => 'SomethingController@show',
]);
$router->patch('', [
'as' => 'edit_something',
'uses' => 'SomethingController@update',
]);
$router->delete('', [
'as' => 'delete_something',
'uses' => 'SomethingController@destroy',
]);
});
public function show(Request $request) {
$something = $request->attributes->get('fetchedObject');
return new JsonResponse($something);
}