title: REST API post field validation Laravel 5.1
body: <p>I need to check if I have all posted variables are required or else throw error.
  Till Now I am doing like this</p>
  
  <p>Routes.php</p>
  
  <pre><code>Route::post('/api/ws_fetchuser', 'UserController@fetch_user_details');
  </code></pre>
  
  <p>UserController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Http\Requests;
  use Illuminate\Http\Request;
  use App\User;
  
  class UserController extends Controller
  {
    public function fetch_user_details(Request $request)
      { 
          if(!empty($request) &amp;&amp; $request-&gt;id!='')
          {
              print_r($request-&gt;id);    
          }
          else
          {
              return response(array(
              'error' =&gt; false,
              'message' =&gt;'please enter all form fields',
              ),200);        
          }
  
      }
  }
  </code></pre>
  
  <p>I am checking like this <code>$request-&gt;id!=''</code>, is there any validation rules or methods which I can use to check id is required field.</p>
  
  <p>I have added this validation in my controller as well but what if id is not present how can I show the error?</p>
  
  <p>Updated Validation Code:</p>
  
  <pre><code>public function fetch_user_details(Request $request)
      { 
          $this-&gt;validate($request, [
          'id' =&gt; 'required'
          ]);
  
          print_r($request-&gt;id);
  
      }
  </code></pre>