sanca

multiple file validation

Aug 21st, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. /** ===== FILE: app\Http\Requests\validateFormDocument ====== */
  2. public function rules()
  3. {
  4.   return [
  5.    'caption.*' => 'required',
  6.    'jenis.*' => 'required',
  7.    'gambar.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
  8.   ];
  9. }
  10.  
  11. public function messages()
  12. {
  13.   // ??? Custom validation messages nya seperti apa..?
  14. }
  15.  
  16. /** ===== FILE: app\Http\Controllers\Document ======= */
  17.  
  18. public function store(validateFormDocument $request)
  19. {
  20.   ...
  21. }
  22.  
  23.  
  24. /** ===== FILE: resources\views\form ======= */
  25. <form id="formnya" method="POST" action="route('doc.store')" enctype="multipart/form-data">
  26.   @csrf
  27.   <input type="text" name="docname" >
  28.   <!-- disini sebenarnya gambar bertambah ketika addRow button menggunakan Javascript
  29.   tapi anggap saja gambar sudah ada di form.
  30.   -->
  31.   <div id="rowGambar">
  32.    <div id="row_1">
  33.     <input type="text" name="caption[]" >
  34.     <input type="text" name="jenis[]" >
  35.     <input type="file" name="gambar[]"
  36.    </div>
  37.    <div id="row_2">
  38.     <input type="text" name="caption[]" >
  39.     <input type="text" name="jenis[]" >
  40.     <input type="file" name="gambar[]"
  41.    </div>
  42.    <div id="row_3">
  43.     <input type="text" name="caption[]" >
  44.     <input type="text" name="jenis[]" >
  45.     <input type="file" name="gambar[]"
  46.    </div>
  47.   </div>
  48. </form>
  49.  
  50.  
Add Comment
Please, Sign In to add comment