rest api expand

This commit is contained in:
2024-10-07 11:31:16 +03:00
parent 160c381abc
commit 5fe6bd9629
3 changed files with 13 additions and 25 deletions

View File

@ -14,30 +14,9 @@ class PostRestController extends RestController
$this->model = new Post();
}
#[NoReturn] public function actionView($id): void
protected function expand(): array
{
$model = $this->model->where("id", $id)->first();
$model->load("user");
$res = [];
if ($model){
$res = $model->toArray();
}
$this->renderApi($res);
return ["user"];
}
#[NoReturn] public function actionDelete($id): void
{
$model = $this->model->where("id", $id)->first();
$model->load("user");
$res = [];
if ($model){
$res = $model->toArray();
}
$model->delete();
$this->renderApi($res);
}
}