Answer the question
In order to leave comments, you need to log in
How to update laravel data correctly?
Guys, can you tell me how to correctly update the data in Laravel,
I thought so, but the code does not work, you can correct me)
public function update(Request $request,$id){
$user = Crud::find($id);
$update = $user->update([
'name' => $request->input('name'),
'email' => $request->input('email')
]);
$user->save();
return redirect('/')->with('update', 'Вы успешно Изменили Данные');
}
Answer the question
In order to leave comments, you need to log in
1) update itself calls save (save must be removed)
2) You can use magic and the final version will be like this
public function update(Request $request, Crud $crud){
$crud->update([
'name' => $request->get('name'),
'email' => $request->get('email')
]);
return redirect('/')->with('update', 'Вы успешно Изменили Данные');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question