Package Data | |
---|---|
Maintainer Username: | WRonX |
Maintainer Contact: | wronx@wronx.net (Marcin "WRonX" Wronka) |
Package Create Date: | 2018-07-19 |
Package Last Update: | 2018-10-15 |
Language: | PHP |
License: | WTFPL |
Last Refreshed: | 2024-11-15 15:11:43 |
Package Statistics | |
---|---|
Total Downloads: | 1,050 |
Monthly Downloads: | 8 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
IMPORTANT: This package is a work in progress, it it not stable by any means.
Use responsibly! Or don't use at all and wait for v1.0.
It was created to avoid repetitive 404 (and other) checks when hitting CRUD endpoints of API.
(well, it will be in stable version... I hope...)
composer require wronx/lumen-rest-object-fetch-middleware
bootstrap/app.php
:$app->routeMiddleware([
// ...
'object' => WRonX\RestObjectFetch\RestObjectFetchMiddleware::class,
]);
routes/web.php
assign it to route which requires id
parameter, giving it model's class name:$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);
}
If you want to contribute, please wait. Until stable version arrives I want to shape this package in my specific way. Later on, pull requests will be welcome.
Copyright © 2016 github.com/WRonX
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details