title: return Validator response in custom format in laravel?
body: <p>I am using validators as </p>
  
  <pre><code>   $validator = Validator::make($request-&gt;all(), [
          'name' =&gt; 'required|max:255',
          'phone' =&gt; 'required|max:10|unique:users',
          'email' =&gt; 'required|email|max:255|unique:users',
          'password' =&gt; 'required|min:6',
      ]);
  
      if ($validator-&gt;fails()) {
          return response()-&gt;json(['error'=&gt;$validator-&gt;errors()], 401);            
      }
  </code></pre>
  
  <p>this gives response in format below:</p>
  
  <pre><code> {
      "error": {
          "phone": [
              "The phone has already been taken."
          ],
          "email": [
              "The email has already been taken."
          ]
      }
  }
  </code></pre>
  
  <p>I want response as</p>
  
  <pre><code>{
  "error": 1,
  "error_msg": "The phone has already been taken."
  }
  </code></pre>
  
  <p>Just one error should show and that too in above format.</p>