0

I have this data

$date = '21-10-1996';
$id = '1';
$count = 0;

And now I want to update the $count data when every $date data and $id data are updated in the livewire form.

how to properly do that?

I have done

public function updateddate($selected_date){
    return($selected_date);
}
public function updatedid($selected_id){
    $count = select:where('id', $selected_id)->where('date', $this->updateddate($this->date)->count);
}

but the data will only be updated if I change the $id only. if I change the $date, I have to update the $id after that so that the $count data is updated.

Ilham Riski
  • 89
  • 1
  • 1
  • 11
  • but this is going to be achieved on form submit ? – Prospero Oct 31 '21 at 18:37
  • @Prospero yes I will save it when I submit, if I update the time to the $date and $id data the data will be saved during the update but if I update the $date again, the data will be the same as before until I update the $id data – Ilham Riski Nov 01 '21 at 00:56

1 Answers1

0

the updated hook is camelcase, so in your cases must be:

public $id,$dates,$count = 0;

public function udpatedId($value) {}

// or

public function updatedDates($value) {}

If your function must resolve the logic after form submit, you can do it without the updated hook. Otherwise, you only need to do it on updatedId hook

public function updatedId($value)
{
   if($value) {
      $this->count = User::where('id',$value)->where('date',$this->date)->count();
   }   
}
Prospero
  • 2,190
  • 2
  • 4
  • 18