From 9823a6ad8e8939f2d30e17408239f34dd1cdc706 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Mon, 7 Oct 2024 16:57:26 +0300 Subject: [PATCH] reast api update --- kernel/RestController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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");