Merge pull request #48 from AfzalH/master

Some fixes for latest lumen. Also added customized response for NOT_FOUND and NO_CONTENT response
This commit is contained in:
Amine Ben hammou 2017-10-23 00:12:29 +02:00 committed by GitHub
commit a6008f4a40
3 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,7 @@
class {{name}} extends Controller {
const MODEL = "{{model}}";
const MODEL = '{{model}}';
use RESTActions;

View File

@ -53,6 +53,12 @@ trait RESTActions {
protected function respond($status, $data = [])
{
if($status == Response::HTTP_NO_CONTENT){
return response(null,Response::HTTP_NO_CONTENT);
}
if($status == Response::HTTP_NOT_FOUND){
return response(['message'=>'resource not found'],Response::HTTP_NOT_FOUND);
}
return response()->json($data, $status);
}

View File

@ -1,8 +1,8 @@
/**
* Routes for resource {{resource}}
*/
$app->get('{{resource}}', '{{controller}}@all');
$app->get('{{resource}}/{id}', '{{controller}}@get');
$app->post('{{resource}}', '{{controller}}@add');
$app->put('{{resource}}/{id}', '{{controller}}@put');
$app->delete('{{resource}}/{id}', '{{controller}}@remove');
$router->get('{{resource}}', '{{controller}}@all');
$router->get('{{resource}}/{id}', '{{controller}}@get');
$router->post('{{resource}}', '{{controller}}@add');
$router->put('{{resource}}/{id}', '{{controller}}@put');
$router->delete('{{resource}}/{id}', '{{controller}}@remove');