DEV Community

Discussion on: Create a toggle switch in Laravel with Livewire & Tailwind

Collapse
 
aspiess profile image
Aron Spiess • Edited

Could I get some help, I can't seem to pass the row id to the component. The data being passed are all NULL.
Finally it's asking to insert instead of update

data:

 #content: "{"id":"2UnpKYzKmHAjM1AB2auH","data":{"field":null,"hasStock":false},"name":"toggle-button","checksum":"0a9757b5807b1d5c1eb9ac1c0170fa237b4ddf595ac372bc311a229c2 "
Enter fullscreen mode Exit fullscreen mode

model:

      public function mount(Model $model)
      {
          $this->hasStock = (bool) $model->getAttribute($this->field);
      }
Enter fullscreen mode Exit fullscreen mode

view:

         <livewire:toggle-button
          field="stock{{ $person->id }}"
          key="{{ $person->id }}"/>
Enter fullscreen mode Exit fullscreen mode

component:

      public function updating( $field, $value)
      {

        dump(request(),$field, $value);

        //$model = new \App\CauseSignupsModel;
        //$model->setAttribute($field, $value)->update();
      }
Enter fullscreen mode Exit fullscreen mode