reast api update
This commit is contained in:
parent
4c75c9469b
commit
9823a6ad8e
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user