title: Why is my field validated even if it's not required?
body: <p>I have a request that takes several input. I want the 'salary' input to be validated <strong>only</strong> if the salary_type is equal to &quot;exact&quot;. Else, I don't want to have any message about it.</p>
  <p>However, now, even if salary_type is equal to &quot;range&quot;, I still get an error that &quot;salary must be an integer&quot;.</p>
  <p>How can I make sure there isn't any error unless the field is required?</p>
  <p>Thanks!</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use Illuminate\Foundation\Http\FormRequest;
  
  class StoreJobOfferRequest extends FormRequest
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          return [
              'title' =&gt; 'required|string|min:3',
              'description' =&gt; 'required|string|min:10',
              'city' =&gt; 'required|string|min:3',
              'salary_type' =&gt; 'required|in:range,exact',
              'min_salary' =&gt; 'required_if:salary_type,range|integer|min:0',
              'max_salary' =&gt; 'required_if:salary_type,range|integer|min:0',
              'salary' =&gt; 'required_if:salary_type,exact|integer|min:0',
              'fieldsOfWork' =&gt; 'required|exists:field_of_works,id',
              'job_type.*' =&gt; 'required|exists:job_types,id',
              &quot;trainings.*&quot; =&gt; 'required|exists:trainings,id',
              &quot;availability.*&quot; =&gt; 'required|exists:trainings,id'
          ];
      }
  }
  
  </code></pre>