php - old helper with updateOrcreate
i'm trying to use old helper with updateorcreate. I have a textarea for an about field. If the user has published something, the old text should be displayed when he wants to update. When I try to use the old helper {{old('about', $profile->about)}}
I get this error: Attempt to read property "about" on null. When I remove the old helper, write something then add the old helper, then it works. I understand that it is trying to retrieve something that isn't in the database. I tried making the about field nullable but it still doesn't work
Answer
Solution:
Seems that $profile
is null in your case. Maybe a create form instead of edit?
Try to :
{{old('about', $profile->about ?? '')}}
or
{{old('about', optional($profile->about))}}
So that it uses empty string when old does not exist and profile either.
Source