title: REST API Request parameter validation Laravel
body: <p>I am new to API with Laravel. I am trying to validate parameters sent into POST request through the Laravel's validate method.</p>
  
  <p>Following data is the only parameter I am sending through the POST request. I want to validate device_id for uniqueness using Laravel's validate method.  </p>
  
  <pre><code>data =&gt; {"device_id":"xxxxxx2C-9EA3-4FFB-B26D-E8E483xxxxxx","password":"ANVp285x","user_type":"1"} 
  </code></pre>
  
  <p>I can validate the only data parameter however there is no proper response or error message it's throwing exception. My main motive is to validate <code>device_id</code>, <code>password</code> and <code>user_type</code>.</p>
  
  <p>Here's my controller's store</p>
  
  <pre><code>public function store(Request $request) {
  
      try {
          $result = $this-&gt;validate($request, [
              'data' =&gt; 'required',
  //                'data.device_id' =&gt; 'required|unique:users|max:60',
  //                'data.password' =&gt; 'required|min:6|confirmed',
  //                'data.user_type' =&gt; 'required',
          ]);
          $user = new User;
  //        Parameters from request
          $data = json_decode($request-&gt;data, TRUE);
          $user-&gt;device_id = $data['device_id'];
          $user-&gt;password = bcrypt($data['password']);
          $user-&gt;u_type = $data['user_type'];
  
  //        Parameters to be generated
          $user-&gt;qr_code_image = "test_qr_code.png";
          $user-&gt;access_code = MyHelper::generate_access_code();
          $user-&gt;save();
          $user = User::find($user-&gt;id);
          $result = Fractal::item($user, new UserTransformer)-&gt;getArray();
          if (!empty($result['data'])) {
              $result['status'] = TRUE;
              $result['message'] = 'Success';
          } else {
              $result['status'] = FALSE;
              $result['message'] = 'Failed';
          }
      } catch (\Exception $e) {
          $result['status'] = FALSE;
          $result['message'] = 'Failed';
      }
      return $result;
  }
  </code></pre>