rest api expand
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user