Stack Overflow Asked by Piotrek on November 4, 2021
What is wrong with this function? I ve got error on this line:
$user->update($input);
Call to a member function update() on null
$input = $request->all();
if ($input == NULL) {
return redirect()->route('users.index');
}
else {
$user = User::find($id);
$user->update($input);
DB::table('model_has_roles')->where('model_id', $id)->delete();
$user->assignRole($request->input('roles'));
return redirect()->route('users.index')
->with('success', 'User updated successfully');
}
You can check if user has some data. Or you can findOrFail()
instead of find()
.
$input = $request->all();
if ($input == NULL) {
return redirect()->route('users.index');
}
else {
$user = User::find($id);
if ($user) {
$user->update($input);
DB::table('model_has_roles')->where('model_id', $id)->delete();
$user->assignRole($request->input('roles'));
}
return redirect()->route('users.index')
->with('success', 'User updated successfully');
}
Answered by Habib on November 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP