Learner\Http\Controllers\Admin\CategoryController::update PHP Method

update() public method

admin/categories/update/{id}
public update ( integer $id ) : Illuminate\Http\JsonResponse
$id integer
return Illuminate\Http\JsonResponse
    public function update($id)
    {
        $form = $this->categories->getUpdateForm();
        if (!$form->isValid()) {
            return $this->responseJson(['errors' => $form->getErrors()], 400);
        }
        $cateData = $form->getInputData();
        $data = ['name' => $cateData['name']];
        if (key_exists('image', $cateData)) {
            $imagePath = ImageManager::changeCategoryImage($cateData['image'], $this->categories->findImageById($id));
            $data['image'] = $imagePath;
        }
        $category = $this->categories->update($id, $data);
        return $this->responseJson(['message' => '分类修改成功', 'data' => $category]);
    }