I have had this problem many times now and I really wonder why this is happening.
Here is its latest occurrence:
public function updateBirthDate(Request $request)
{
try {
$request->validate([
'email' => 'required|email',
'birthDate' => 'required|date_format:Y-m-d',
]);
$user = User::where('email', $request->email)->first();
$user->profile()->update(['birth_date' => Carbon::parse($request->birthDate)->timestamp]);
return response_success([], __FUNCTION__, __('verification.user_data_updated'));
} catch (Exception $exception) {
Log::error(__FUNCTION__, compact('exception'));
return response_error(__FUNCTION__, $exception->getMessage());
}
}
The code above didn't change 'birth_date' in database when I sent the request through Postman.
But when I ran the line below in tinker, it changed 'birth_date' in database:
$user->profile()->update(['birth_date' => Carbon::parse('1990-01-01')->timestamp]);
I suppose this is a bug in this Laravel version.
$request->validate()? I can see a lot of points of failure with your code that wouldn't be there if you simply didUser::where('email', '[email protected]')->first();, then$user->profile->update([...])intinker. Might be worth editing your question and provide some more clarification.$request->validate()can send an HTTP redirect to PostMan if the headers being sent are incorrect,User::where(...)->first()can returnnull, andnull->profile()->update()would fail.$user->profile()is aBuilderinstance, not a singleProfileinstance, and it could simply silently fail if the User doesn't have a Profile, or update the wrong one if the User has multiple profiles (I think; I've never tried$user->profile()->update()vs$user->profile->update). That's what I meant by "many possible points of failure".