reast api update
This commit is contained in:
parent
4c75c9469b
commit
9823a6ad8e
@ -76,7 +76,6 @@ class RestController
|
|||||||
|
|
||||||
#[NoReturn] public function actionStore(): void
|
#[NoReturn] public function actionStore(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
foreach ($this->model->getFillable() as $item){
|
foreach ($this->model->getFillable() as $item){
|
||||||
@ -87,6 +86,21 @@ class RestController
|
|||||||
$this->renderApi($this->model->toArray());
|
$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
|
#[NoReturn] protected function renderApi(array $data): void
|
||||||
{
|
{
|
||||||
header("Content-Type: application/json");
|
header("Content-Type: application/json");
|
||||||
|
Loading…
Reference in New Issue
Block a user