问题描述
我不明白它在哪里阻塞。如果我用 update()
方法替换 create()
,它会起作用,或者如果我删除广播,更新会起作用。如何通过广播更新?
public function SendToMarket(Request $request,$id)
{
$card = auth()->user()->cards()->findOrFail($id)->update([
'market_id' => $request["_market"],'borderStyle_id' => $request["_borderStyle"],'price' => $request["_price"]
]
);
$notification = array(
'message' => 'Card Send to market Successfully !','alert-type' => 'warning'
);
broadcast(new FetchCardEvent($card->load('user')))->toOthers();
return redirect()->route('user.cards')->with($notification);
}
解决方法
update()
不返回 Modal 实例。相反,它会返回一个 Boolean。
使用 firstOrFail()
取回卡片后,您应该单独更新它。
public function SendToMarket(Request $request,$id) {
$card = auth()->user()->cards()->findOrFail($id);
$card->update([
'market_id' => $request["_market"],'borderStyle_id' => $request["_borderStyle"],'price' => $request["_price"]
]);
$notification = array(
'message' => 'Card Send to market Successfully !','alert-type' => 'warning'
);
broadcast(new FetchCardEvent($card->load('user')))->toOthers();
return redirect()->route('user.cards')->with($notification);
}