I want to perform some action on the success of post call
shoaibanwar opened this issue · comments
Hi,
I want to perform some action on the success of post call,
I tried the following code from documentation. Included it in my base controller, but may be it is not the right way
$this->onRest('req.post.resource.render', function($model, $relations=[], $visibleProperties=[], $hiddenProperties=[]) {
$this->renderJSON([
'type' => 'rest',
'success' => 'true',
'message' => "Record Created",
'totalCount' => "1",
'modelName' => get_class($model),
'relations' => $relations,
'visibleProperties' => $visibleProperties,
'hiddenProperties' => $hiddenProperties,
'data' => $model,
]);
});
There are many ways to do this. I think the best way to do this is with a 'post.filter':
$this->onRest('post.filter.req.post.resource.render', function($json) {
if(json_decode($json)->success) {
//DO YOUR POST SUCCESS ACTION
}
return $json //Mixed[JSON Sting, ARRAY]
});