title: Laravel, How to ignore (except) some fields when update model using json and laravel
body: <p>The function below is to update user information, I need to validate if email is not duplicated, also to ignore password if its field left empty, I don't why this function not working!</p>
  
  <pre><code>public function update(Request $request, $id)
  {
  
  $this-&gt;validate($request-&gt;all(), [
          'fname' =&gt; 'required',
          'email' =&gt; 'required|email|unique:users,email,'.$id,
          'password' =&gt; 'same:confirm-password',
          'roles' =&gt; 'required'
      ]);
  
  
      $input = $request-&gt;all()-&gt;except(['country_id', 'region_id']);
      if(!empty($input['password'])){ 
          $input['password'] = Hash::make($input['password']);
      }else{
          $input = array_except($input,array('password'));    
      }
  
      $user = User::find($id);
      $user-&gt;update($input);
      DB::table('model_has_roles')-&gt;where('model_id',$id)-&gt;delete();
      $user-&gt;assignRole($request-&gt;input('roles'));
      return response()-&gt;json(array('data' =&gt; trans('message.success')));
  }
  </code></pre>