title: What is the Laravel way to check if the POST Request has a field left empty?
body: <p>The requirement was to update user roles. The role can be empty(left blank), one, or more than one as provided in the form field <code>roles[]</code>.</p>
  
  <p>Here is the view form:                   </p>
  
  <pre><code>@foreach ($roles as $role)
    &lt;div class="checkbox"&gt;
       &lt;label&gt;&lt;input name="roles[]" type="checkbox" value="{{$role-&gt;id}}" {{ $user-&gt;roles-&gt;contains($role-&gt;id) ? 'checked' : '' }}&gt;{{$role-&gt;name}}&lt;/label&gt;
    &lt;/div&gt;
  @endforeach
  </code></pre>
  
  <p>The condition inside <strong>UserController::update()</strong> is:</p>
  
  <pre><code>if ($request-&gt;roles) {
      // update user roles
  }
  </code></pre>
  
  <p>Everything works fine except for one case. Sometimes the user has to stay without any role.</p>
  
  <p><code>if($request-&gt;roles)</code>, <code>isset($request-&gt;roles)</code>, and <code>!empty($request-&gt;roles)</code> .. are all giving the same old fashioned reply(<code>null</code>, <code>''</code>, <code>true/flase</code>).</p>
  
  <p>Case: <em>when there is one or more role(s) assigned</em>:</p>
  
  <pre><code>  +request: ParameterBag {#41 ▼
      #parameters: array:6 [▼
        "_method" =&gt; "PUT"
        "_token" =&gt; "a8oIPQFBMbhjanikX8v83qeOcfRE0N4UKTcTQDig"
        "name" =&gt; "New User Name"
        "email" =&gt; "newuser@testserver.asap"
        "password" =&gt; ""
        "roles" =&gt; array:2 [▼
          0 =&gt; "2"
          1 =&gt; "3"
        ]
      ]
    }
  </code></pre>
  
  <p>Case: <em>when there no role assigned OR need to remove(detach) the previously assigned role</em>:</p>
  
  <pre><code>  +request: ParameterBag {#41 ▼
      #parameters: array:5 [▼
        "_method" =&gt; "PUT"
        "_token" =&gt; "a8oIPQFBMbhjanikX8v83qeOcfRE0N4UKTcTQDig"
        "name" =&gt; "New User Name"
        "email" =&gt; "newuser@testserver.asap"
        "password" =&gt; ""
      ]
    }
  </code></pre>
  
  <p>So the question (requirement) is: </p>
  
  <p><strong>How to differentiate when the field value of an HTML Post form has been submitted as empty(unchecked here) or if there was no such a field in the view form?</strong>
  <strong>Is there an eloquent* way in Laravel to find/list the form fileds from the <code>Request</code> object?</strong></p>
  
  <p>[PS: Trying another hidden field or do some frontend jQuery will not be appreciated]</p>