【问题标题】:Problem with broadcasting and websocket in LaravelLaravel 中的广播和 websocket 问题
【发布时间】:2021-03-31 16:19:55
【问题描述】:

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

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

【问题讨论】:

    标签: laravel websocket real-time laravel-8 broadcasting


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-02-05
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多