0
votes

I have one larvale blade with bellow div and text box

<td class="border px-4 py-2" x-data="{dropdown: false,nSValue:{{ $item->price}}, idValue: {{$item->id}}}" @click.away="dropdown = false">

<input x-model="nSValue" type="number" placeholder="0">

</td>

As you have in td I have 3 values in x-data

1. dropdown=false
2. nSValue which is price
3. idValue which is value

also now I am showing that

nSValue

in text box

how can I get values of dropdown & nSValue & idValue in contoller? I try getting values like $nSValue its not working

1

1 Answers

0
votes

There a few ways of doing this. Why do you need those values in the x-data if you are not using them in Alpine?

If this is a traditional form submit you could just do:

<input type="hidden" name="price" value="{{ $item->price }}" />

if you really want to fully use Alpine you could do something like

<td class="border px-4 py-2" x-data="{
  dropdown: false,
  nSValue:{{ $item->price}}, 
  idValue: {{$item->id}},
  submit() {
    fetch('endpoint', {
      method: 'POST'
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(this.data),
    }
  }
}" @click.away="dropdown = false">

  <input x-model="nSValue" x-on:change="submit" type="number" placeholder="0">

</td>