Search code examples
phplaravel-bladedisabled-input

How to disable an input field if it has value in blade.php


I am trying to disabled an input field if it has value. Somehow, it looks like this:

<input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" placeholder="">

I have tried adding like:

<input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" 
  disabled= {{ $user['sex'] == null ? disabled :'' }}  >

But it is not working. I am using blade.php by the way.


Solution

  • Try this

      <input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" {{ $user['sex'] ? '' : 'disabled' }}  >