Livewire传递id用于更新



如何从列表传递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()中调用function

试试这个

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

then in component

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

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

相关内容

  • 没有找到相关文章

最新更新