bernandotorrez

KaryawanIndex.php

Oct 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Livewire\Pages\Karyawan;
  4.  
  5. use Livewire\Component;
  6.  
  7. class KaryawanIndex extends Component
  8. {
  9.  
  10.     /**
  11.      * this is a global variable to work with
  12.      * wire:model="employee_number",
  13.      * wire:model="employee_name"
  14.      * wire:model="gender"
  15.      */
  16.     public $employee_number, $employee_name, $gender;
  17.  
  18.     /**
  19.      * giving validation rule
  20.      * this is a global validation rule
  21.      */
  22.  
  23.     protected $rules = [
  24.         'employee_number'   => 'required|min:10',
  25.         'employee_name'     => 'required|min:5',
  26.         'gender'            => 'required'
  27.     ];
  28.  
  29.     /**
  30.      * will run after render function
  31.      */
  32.     public function mount()
  33.     {
  34.         $this->resetData();
  35.     }
  36.  
  37.     /**
  38.      * This function is to make real-time validation to form, when the user do a change
  39.      */
  40.  
  41.     public function updated($propertyName)
  42.     {
  43.         $this->validateOnly($propertyName);
  44.     }
  45.  
  46.     /**
  47.      * this function will used to reset input field in a form with the wire:model
  48.      */
  49.     public function resetData()
  50.     {
  51.         $this->employee_number = '';
  52.         $this->employee_name = '';
  53.         $this->gender = '';
  54.     }
  55.  
  56.     public function render()
  57.     {
  58.         return view('livewire.pages.karyawan.karyawan-index');
  59.     }
  60.  
  61.     /**
  62.      * this function will used to add data to the karyawan table
  63.      */
  64.  
  65.     public function addData() {
  66.         $this->validate();
  67.     }
  68. }
  69.  
Add Comment
Please, Sign In to add comment