title: Laravel validate unique mobile out of the user that is updating it on API level?
body: <p>as <a href="https://laravel.com/docs/5.2/validation#rule-unique" rel="nofollow noreferrer">this link</a> and <a href="https://stackoverflow.com/q/40942367/1830228">this link</a> couldn't help me i'm wondering how can i validate unique mobile out of the user that is updating it on API level. for example:</p>
  
  <pre><code>public function register(Request $request)
  {
      try {
          $user = User::whereMobileNumber($request-&gt;mobile_number)-&gt;first();
  
          /*VALIDATION IF USER NOT FOUND*/
          if ($user == null) {
              $validator = Validator::make($request-&gt;all(), [
                  'mobile_number' =&gt; 'required|string|unique:users|min:11|max:11',
              ]);
          }else{
              /*VALIDATION IF USER HAVE DATA AND IGNORE CHECK MOBILE NUMBER*/
              $validator = Validator::make($request-&gt;all(), [
                  'mobile_number' =&gt; 'required|string|min:11|max:11|unique:users,mobile_number,'.$user-&gt;mobile_number,
              ]);
          }
  
          if ($validator-&gt;fails()) {
              return response(['data' =&gt; $validator-&gt;errors()-&gt;all(), 'status' =&gt; $user-&gt;mobile_number], 200);
          }
  
          ...
      } catch (\Exception $ex) {
          return response(['data' =&gt; $ex-&gt;getMessage(), 'status' =&gt; '5'], 200);
      }
  }
  </code></pre>
  
  <p>unfortunately i get this error:</p>
  
  <pre><code>The mobile number has already been taken.
  </code></pre>
  
  <p>what happen in that and how can i resolve this problem?</p>