如何从列表传递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