title: how to passing validation laravel controller to sweet alert swal
body: <p>I first tried sweet alert here. I want to create a data input eror validation list displayed in sweet alert, first I tried not to fill all textfields so the result would be a list of anything that misinput or not filling in on textfield and being sampled in sweet alert. I've tried but only get last his value is just a list of unbending data, please help me</p>
  
  <p>controller</p>
  
  <pre><code> public function simpanpegawai(Request $req)
      {
          $messages = [
              'nama.required' =&gt; 'Field Nama Gak Boleh Kosong',
              'nama.min' =&gt; 'Field nama tidak boleh kurang dari 5 kata',
              'nama.regex' =&gt; 'Field nama tidak boleh angka',
              'alamat.required' =&gt; 'Field Alamat Gak Boleh Kosong',
              'alamat.min' =&gt; 'Field alamat tidak boleh 5 kata',
              'tempat_lahir.required' =&gt; 'Field tempat lahir harus diisi !',
              'tempat_lahir.regex' =&gt; 'field Tempat lahir tidak boleh ada angka',
              'tgl_lahir.required' =&gt; 'Field Tanggal Lahir harus diisi !',
              'tgl_lahir.date' =&gt; 'Field Tanggal Lahir harus format tanggal!',
              'pendidikan_terkahir.not_in' =&gt; 'Field pendidikan terkahir Gak Boleh Kosong',
              'no_telp.required' =&gt; 'Field no telpon Gak Boleh Kosong',
              'no_telp.min' =&gt; 'Field no telpon Harus minimal 10 ',
              'jkel.not_in' =&gt; 'Field jenis kelamin harus diisi !',
              'id_jabatan.not_in' =&gt; 'Field jabatan harus diisi !',
              'status.not_in' =&gt; 'Field status harus diisi !',
              ];
  
          $validator = \Validator::make($req-&gt;all(), [
              'nama' =&gt; 'required|min:5|regex:/^[a-zA-Z]+(([\',. -][a-zA-Z ])?[a-zA-Z]*)*$/',
              'alamat' =&gt; 'required|min:5',
              'no_telp' =&gt; 'required|min:10',
              'tempat_lahir' =&gt; 'required|min:5|regex:/^[a-zA-Z]+(([\',. -][a-zA-Z ])?[a-zA-Z]*)*$/',
              'tgl_lahir' =&gt; 'required|date',
              'pendidikan_terkahir' =&gt; 'not_in:0',
              'jkel' =&gt; 'not_in:0',
              'id_jabatan' =&gt; 'not_in:0',
              'status' =&gt; 'not_in:0',
          ], $messages);
          if ($validator-&gt;fails()) {
              return response()-&gt;json(['errors' =&gt; $validator-&gt;errors()-&gt;all()]);
          } else {
              $user = new \App\User;
              $user-&gt;name = $req-&gt;nama;
              $user-&gt;role = $req-&gt;id_jabatan;
              $user-&gt;username = $req-&gt;nama;
              $user-&gt;password = bcrypt($req-&gt;no_telp);
              $simpan = $user-&gt;save();
  
  
              $req-&gt;request-&gt;add(['user_id' =&gt; $user-&gt;id]);
              $pegawai = \App\PegawaiModel::create($req-&gt;all());
              if ($simpan == 1) {
  
                  $status = "Tersimpan";
  
              } else {
                  $status = "Gagal";
              }
              echo json_encode(array("status" =&gt; $status));
          }
      }
  </code></pre>
  
  <p>sweet alert in blade script</p>
  
  <pre><code>$.ajax({
                  url: url,
                  type: "POST",
                  data: $('#formpegawai').serialize(),
                  dataType: "JSON",
                  success: function (data) {
                      if (data.errors) {
  
                          jQuery.each(data.errors, function (key, value) {
                              swal({
                                  title: "Pesan Eror",
                                  text: value,
                                  timer: 5000,
                                  showConfirmButton: false,
                                  type: "error"
                              })
                          });
  
                      } else {
                          swal({
                              text: data.status,
                              timer: 5000,
                              icon:"success",
                              showConfirmButton: false,
                              type: "error"
                          })
                          $('#modal_form').modal('hide');
                      }
                  },
                  error: function (request, status, error) {
  
                  }
              });
  </code></pre>
  
  <p>picture
  <a href="https://i.stack.imgur.com/yvM7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yvM7x.png" alt="enter image description here"></a></p>