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

@ -11,6 +11,12 @@ class RestController
protected Model $model;
protected function expand(): array
{
return [];
}
#[NoReturn] public function actionIndex(): void
{
$request = new Request();
@ -29,7 +35,11 @@ class RestController
#[NoReturn] public function actionView($id): void
{
$expand = $this->expand();
$model = $this->model->where("id", $id)->first();
if ($expand){
$model->load($expand);
}
$res = [];
if ($model){
$res = $model->toArray();