What is the best way to update my object in the database from my request?
Currently I am updating every single field and then saving the object:
$user = User::findOrFail($id);
$user->username = $request->username;
$user->role = $request->role;
$user -> save();
Also it is not required to have all the fields present. One request can update the role of the user, but other can update only the username.
How can I loop and update only the present fields from the request or is there a way to pass the whole request as a paramater and setting only the id and eloquent to know what to do with it?