reast api update

This commit is contained in:
Билай Станислав 2024-10-07 16:57:26 +03:00
parent 4c75c9469b
commit 9823a6ad8e

View File

@ -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");