Error status 500 request wire:model Data Binding

Hai,

I was confused when trying 2 times the request with date pikaday on change

the first request was successful but the second request failed with the 500 status code,

Is there something wrong with worklfow?

succes request first

error request second at i change date

code my live wire

class Employees extends Component

{
public $date;

public $data;


public function cek()
{
    
    $tanggal = \Carbon\carbon::parse($this->date)->todatestring();
    
    $data = DB::select("
        select * from pegawai where hire_date = '".$tanggal."'     
    ");

   $this->data = $data;
}

public function render()
{
    return view('livewire.employees');
}

}

livewire view

  <div class="form-inline mt-3" wire:ignore>
  <input type="text"  class="form-control" placeholder="Tanggal" id="datepicker" autocomplete="off">
  {{-- <input type="date"  class="form-control" placeholder="Tanggal" wire:model="date" autocomplete="off"> --}}
  <button wire:click = "cek" class="btn btn-info">Proses</button>
<script>
var picker = new Pikaday({
    field: document.getElementById('datepicker'),
    format: 'D-MMM-YYYY',
    yearRange: [1990, 2030],
    onSelect: function() {
        console.log(this.getMoment().format('Do MMMM YYYY'));
    }
});   
$('#datepicker').on('change', function (e) {
            @this.set('date', e.target.value);
});

I have found an error in my code

first, I will pass data to the render from the documentation so the data must be initialized in protected $data as array then in passing to view [‘data2=> $ this-> data’]

and not in public paramters

class Employees extends Component
{
public $date ;
public $cari;

protected $data ;

public function mount()
{
    if(\Carbon\carbon::now() >= \Carbon\carbon::now()->hour(19))
    {
        $actual = \Carbon\carbon::today()->todatestring();
    }else
    {
        $actual = \Carbon\carbon::today()->subday()->todatestring();
    }
   

    $data = DB::select("
        select * from pegawai where hire_date <= '".$actual."'      
    ");

    $this->data = $data;
}

public function cek()
{
    
    $tanggal = \Carbon\carbon::parse($this->date)->todatestring();
    
    $data = DB::select("
        select * from pegawai where hire_date = '".$tanggal."'   and first_name like '%".$this->cari."%'   
    ");

   $this->data = collect($data);


}


public function render()
{
   
    return view('livewire.employees',['data2'=>$this->data]);
}

}

View Blade

@forelse ($data2 as $item)

            <tr>

                <td>{{$loop->index+1}}</td>        

                <td>{{$item->first_name}}</td>   

                <td>{{$item->hire_date}}</td> 

                <td>{{$item->salary}}</td> 

            </tr>

            @empty

                <p>No users</p>

            @endforelse

and working :slightly_smiling_face: