Code:
class Mycontroller extends ResourceController
{
protected $modelName = 'App\Models\MyModel';
protected $format = 'json';
public function create(): \CodeIgniter\HTTP\Response
{
try {
$request = $this->request->getJSON();
$resourceID = $this->model->save($request);
$resource = $this->model->asObject()->find($resourceID);
return $this->respond($resource, 201);
} catch (\Throwable $e) {
return $this->handleThrowable($e);
}
}
...
I have been struggling with $this->respond(). I have no idea why it is returning empty result. $resource contains the given object with the data its supposed to return but respond returns empty response for some reason. I get no errors. I am clueless.
In another controller I have pretty much exactly the same code but the stdClass type of resource is created in different way. It works and returns the response as its is supposed to.