diff --git a/kernel/RestController.php b/kernel/RestController.php index 7f5a355..797885f 100644 --- a/kernel/RestController.php +++ b/kernel/RestController.php @@ -76,7 +76,6 @@ class RestController #[NoReturn] public function actionStore(): void { - $request = new Request(); $data = $request->post(); foreach ($this->model->getFillable() as $item){ @@ -87,6 +86,21 @@ class RestController $this->renderApi($this->model->toArray()); } + #[NoReturn] public function actionEdit(int $id): void + { + $request = new Request(); + $data = $request->post(); + + $model = $this->model->where('id', $id)->first(); + + foreach ($model->getFillable() as $item){ + $model->{$item} = $data[$item] ?? null; + } + + $model->save(); + $this->renderApi($model->toArray()); + } + #[NoReturn] protected function renderApi(array $data): void { header("Content-Type: application/json");