title: How to write custom validation rule in controller Laravel?
body: <p>I have default validation rule in controller Laravel:</p>
  
  <pre><code>$validator = Validator::make($request-&gt;all(), [
              'email' =&gt; 'required|email',
              'phone' =&gt; 'required|numeric',
              'code' =&gt; 'required|string|min:3|max:4',
              'timezone' =&gt; 'required|numeric',
              'country' =&gt; 'required|integer',
              'agreement' =&gt; 'accepted'
          ]);
  </code></pre>
  
  <p>I tried this, but dont know how to transfer some parameters inside function:</p>
  
  <pre><code> public function boot()
      {
          Validator::extend('phone_unique', function($attribute, $value, $parameters) {
              return substr($value, 0, 3) == '+44';
          });
      }
  </code></pre>
  
  <p>How can I extent this validation by my own rule? For example I need to validate concatination of inputs:</p>
  
  <pre><code>$phone = $request-&gt;code.' '.$request-&gt;phone
  </code></pre>
  
  <p>After check if <code>$phone</code> are exists in database</p>
  
  <p>I want to use this method:</p>
  
  <pre><code>&gt;  $validator-&gt;sometimes('phone', 'required|alpha_dash|max:25', function
  &gt; ($input) {
  &gt;             if ((Auth::user()-&gt;phone == $input-&gt;phone)) {
  &gt;                 return false;
  &gt; 
  &gt;             } else {
  &gt; 
  &gt;                 $t = User::where("phone", $input-&gt;phone)-&gt;get();
  &gt;                 return ($t-&gt;count() &gt; 0) ? false : false;
  &gt; 
  &gt;             }
  &gt;         });
  </code></pre>
  
  <p>It does not work under all conditions <code>(True, False)</code> inside.</p>
  
  <p>I added new validation <code>nickname_unique</code>:</p>
  
  <pre><code> $validator = Validator::make($request-&gt;all(), [
              'email' =&gt; 'required|email',
              'code' =&gt; 'required|string|min:3|max:4',
              'phone' =&gt; 'required|phone_unique',
              'timezone' =&gt; 'required|numeric',
              'country' =&gt; 'required|integer',
              'nickname' =&gt; 'required|alpha_dash|max:25',
              'agreement' =&gt; 'accepted'
          ], [
              'phone_unique' =&gt; 'Phone already exists!',
              'nickname_unique' =&gt; 'Nickname is busy!',
          ]);
  </code></pre>
  
  <p>It does not work, even not call validation rule below previos:</p>
  
  <pre><code>Validator::extend('nickname_unique', function ($attribute, $value, $parameters, $validator) {
  
              dd("Here");
  
  });
  </code></pre>