Laravel 中的广播和 websocket 问题

问题描述

我不明白它在哪里阻塞。如果我用 update() 方法替换 create(),它会起作用,或者如果我删除广播,更新会起作用。如何通过广播更新?

在 bool 上调用成员函数 load()

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);
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...