Check if the $topic variable exists (Not sure why the variable itself would not be set though)
<input type="text" value="{{old('subject', isset($topic) ? $topic->subject : ' ' )}}"/>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, in a reusable form, I try to handle 3 conditions for a field: old value, edit value, and empty:
<input type="text" value="{{old('subject', $topic ? $topic->subject : ' ' )}}"/>
I was thinking this would work, but it gives a "Undefined variable $topic" error.
How to handle this situation?
Check if the $topic variable exists (Not sure why the variable itself would not be set though)
<input type="text" value="{{old('subject', isset($topic) ? $topic->subject : ' ' )}}"/>
Please or to participate in this conversation.