P粉1569834462023-08-26 00:38:39
先建立一個實例。但我認為這不是真正的問題。
$newGrade = (new Grade())->update($grade); return [ 'status' => 'success', 'grade' => $newGrade, ];
嘗試將您的方法更改如下:
$grade = Grade::findOrFail($request->id); $validatedData = $request->validate([ 'title' => 'required|string', 'slig' => 'string', 'description' => 'string', ]); $grade->update($validatedData); return [ 'status' => 'success', 'grade' => $grade, ];