title: laravel and validation with request
body: <p>I cannot set correctly validation in Laravel.
  Among other functions I have this in the Controller</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Exports\RimborsiExport;
  
  use DB;
  use App\Customers;
  use App\Claims;
  use App\Refunds;
  use App\Services;
  use App\Http\Requests\RefundsPost;
  
  use Excel;
  use DataTables;
  use Redirect;
  use Response;
  
  class RefundsController extends Controller
  {
      public function storeRefundsData(RefundsPost $request){
          dd($request);
          
          //$validated = $request-&gt;validated();
          $customers = Customers::create($request-&gt;all());
          return back()-&gt;with('status', 'Dati Cliente inseriti correttamente');
      }
  
  }
  </code></pre>
  <p>I have also defined a custom Request type</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use Illuminate\Foundation\Http\FormRequest;
  
  class RefundsPost 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()
      {
          $rules = [
              'contr_nom' =&gt; 'required|max:255',
              'contr_cog' =&gt; 'required',
              'polizza' =&gt; 'required',
              'email' =&gt; 'required',
              'targa' =&gt; 'required',
              'iban' =&gt; 'required|iban',
              'int_iban' =&gt; 'required',
          ];
          return $rules;
      }
      
      public function messages()
      {
      return [
          'contr_nom.required' =&gt; &quot;Il Nome Contraente e' obbligatorio&quot;,
          'contr_cog.required'  =&gt; &quot;Il Cognome Contraente e' obbligatorio&quot;,
          'polizza.required'  =&gt; &quot;Il numero di polizza e' obbligatorio&quot;,
          'email.required'  =&gt; &quot;Una mail e' obbligatoria per le comunicazioni&quot;,
          'targa.required'  =&gt; &quot;La targa e' obbligatoria&quot;,
          'data_sin.required'  =&gt; &quot;La data sinistro e' obbligatoria&quot;,
          'iban.required'  =&gt; &quot;Il numero IBAN e' obbligatorio&quot;,
          'int_iban.required'  =&gt; &quot;L'intestatario dell' IBAN e' obbligatorio&quot;,
          'dossier.required'  =&gt; &quot;Il numero di dossier e' obbligatorio&quot;,
          'cliente.required'  =&gt; &quot;Il cliente e' obbligatorio&quot;,
          'stato.required'  =&gt; &quot;Lo stato del rimborso e' obbligatorio&quot;,
          'date_ref.required'  =&gt; &quot;La data della richiesta e' obbligatoria&quot;,
          ];
      }
  }
  </code></pre>
  <p>and i have this blade with the form inside</p>
  <pre><code>    &lt;div class=&quot;container-fluid&quot;&gt;
    &lt;form method=&quot;POST&quot; action=&quot;{{ route('storeRefundsData') }}&quot; novalidate&gt;
        
      {{ csrf_field() }}
  
      &lt;h5 class=&quot;mb-3&quot;&gt;Anagrafica&lt;/h5&gt;      
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;contr_nom&quot;&gt;Nome Contraente&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control @error('contr_nom') is-invalid @enderror&quot; id=&quot;contr_nom&quot; name=&quot;contr_nom&quot; value=&quot;{{old('contr_nom')}}&quot;&gt;
          @error('contr_nom')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;contr_cog&quot;&gt;Cognome Contraente&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control @error('contr_cog') is-invalid @enderror&quot; id=&quot;contr_cog&quot;  name=&quot;contr_cog&quot; value=&quot;{{old('contr_cog')}}&quot;&gt;
          @error('contr_cog')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;polizza&quot;&gt;Numero Polizza &lt;span class=&quot;text-muted&quot;&gt;&lt;/span&gt;&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control @error('polizza') is-invalid @enderror&quot; id=&quot;polizza&quot; name=&quot;polizza&quot; value=&quot;{{old('polizza')}}&quot;&gt;
          @error('polizza')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;
  
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;email&quot;&gt;Email &lt;span class=&quot;text-muted&quot;&gt;&lt;/span&gt;&lt;/label&gt;
          &lt;input type=&quot;email&quot; class=&quot;form-control @error('email') is-invalid @enderror&quot; id=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;tu@esempio.it&quot; value=&quot;{{old('email')}}&quot;&gt;
          @error('email')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;targa&quot;&gt;Targa veicolo&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control @error('targa') is-invalid @enderror&quot; id=&quot;targa&quot; name=&quot;targa&quot; placeholder=&quot;Inserisci la targa&quot; value=&quot;{{old('targa')}}&quot;&gt;
          @error('targa')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;          
      &lt;/div&gt;
      
      &lt;h5 class=&quot;mb-3&quot;&gt;Dati bancari&lt;/h5&gt;
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;iban&quot;&gt;IBAN &lt;span class=&quot;text-muted&quot;&gt;&lt;/span&gt;&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control @error('iban') is-invalid @enderror&quot; id=&quot;iban&quot; name=&quot;iban&quot; placeholder=&quot;Inserisci il tuo IBAN&quot; value=&quot;{{old('iban')}}&quot;&gt;
          @error('iban')
            &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
          @enderror
        &lt;/div&gt;
  
        &lt;div class=&quot;col-md-6 mb-3&quot;&gt;
          &lt;label for=&quot;int_iban&quot;&gt;Intestatario IBAN &lt;span class=&quot;text-muted&quot;&gt;&lt;/span&gt;&lt;/label&gt;
            &lt;input type=&quot;text&quot; class=&quot;form-control @error('int_iban') is-invalid @enderror&quot; id=&quot;int_iban&quot; name=&quot;int_iban&quot; placeholder=&quot;Inserisci l'intestatario dell'IBAN&quot; value=&quot;{{old('int_iban')}}&quot;&gt;
            @error('int_iban')
              &lt;div class=&quot;invalid-feedback&quot;&gt;{{ $message }}&lt;/div&gt;
            @enderror
          &lt;/div&gt;
        &lt;/div&gt;
  
      &lt;hr class=&quot;mb-4&quot;&gt;
      &lt;!-- &lt;button class=&quot;btn btn-primary btn-lg btn-block&quot; type=&quot;submit&quot;&gt;Continue to checkout&lt;/button&gt;--&gt;
      &lt;input type=&quot;submit&quot; class=&quot;btn btn-primary btn-lg btn-block&quot; value=&quot;Salva&quot;&gt;
      
      @if (session('status'))
      &lt;div class=&quot;alert alert-success&quot;&gt;
          {{ session('status') }}
      &lt;/div&gt;
      @endif
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I cannot understand why when i click on form submit button to create a new row in the db, it seems that even it doesn't enter Controller function.
  If I use Request instead of custom type RefundsPost it works and store data in the db but obviously without validation.
  How can i fix?
  Thx a lot</p>