How to solve the error of statically calling non-static method 'update'?
P粉032900484
P粉032900484 2023-08-25 21:22:08
0
1
595
<p>This is my function. I am getting an error in it, please help me to resolve this error and tell me why this error is appearing. </p> <pre class="brush:php;toolbar:false;">public function update(Request $request) { $id = $request->id; $grade = Grade::find($id); $grade = $request->validate([ 'title' => 'required|string', 'slig' => 'string', 'description' => 'string', ]); $grade = Grade::update($grade); return [ 'staus' => 'success', 'grade' => $grade, ]; }</pre>
P粉032900484
P粉032900484

reply all(1)
P粉156983446

First create an instance. But I don't think that's the real issue.

$newGrade = (new Grade())->update($grade);

return [
    'status' => 'success',
    'grade'  => $newGrade,
];

Try changing your method as follows:

$grade = Grade::findOrFail($request->id);

$validatedData = $request->validate([
    'title' => 'required|string',
    'slig' => 'string',
    'description' => 'string',
]);

$grade->update($validatedData);

return [
    'status' => 'success',
    'grade' => $grade,
];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template