How to update all records using request->all()
, I have many columns to update.
here is my code for create method which I am using to insert multiple new records which is working fine.
public function store(Request $request)
{
$teacher = new Teacher;
$teacher::create($request->all());
$teacher->save();
return back()->with('message','Teacher Added Successfully!');
}
here is what I tried but it's not working,
public function update(Request $request, Teacher $teacher)
{
$teachers=$request->all();
$teacher->save();
return back()->with('message','Record Successfully Updated!');
}
Instead of this:
public function update(Request $request, Teacher $teacher)
{
$teachers = $request->all();
$teacher->save();
return back()->with('message', 'Record Successfully Updated!');
}
You have to try this:
public function update(Request $request, Teacher $teacher)
{
$input = $request->all();
$teacher->fill($input)->save();
return back()->with('message', 'Record Successfully Updated!');
}
Assuming that you have to create fillable
property in your Teacher
model.
I hope it would be helpful. Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With