用于更新的 Livewire 通行证 ID

Livewire pass id for update

如何传递列表中的 ID 并更新数据库中的项目?

代码

<button class="acceptOrder btn btn-sm btn-success" wire:click="$emit('orderAccepted', {{$order->id}})">Accept order</button>

protected $listeners = ['acceptOrder'];

public function acceptOrder(Order $order)
{
  $order->update(['accepted' => true]);
}

错误

Uncaught SyntaxError: Invalid or unexpected token

可以直接调用wire:click()中的函数

试试这个

<button class="acceptOrder btn btn-sm btn-success" wire:click="orderAccepted('{{ $order->id }}')">Accept order</button>

然后在组件中

public function orderAccepted(Order $order)
{
  $order->update(['accepted' => true]);
}

ref link https://laravel-livewire.com/docs/2.x/actions