why brodcast event cancel deleting from database?

  laravel, lumen, real-time

I use lumen i want to make function do deleting from database at and same time i want to call event for realtime but when i call brodcast delete is not working but when uncomment brodcast delete is working

function:

   public function deleteProductFromBascket()
  {
    try {
      $basket = BasketProduct::where('product_id', '=', $this->request->input('product_id'))
        ->where('basket_id', '=', $this->request->input('basket_id'))->first();


      if ($basket) {

        $basket->delete();
        broadcast(new Stock($basket));

        $res['status'] = true;

        return response($res, 200);
      } else {
        $res['status'] = false;
        $res['message'] = 'product not fond';
        return response($res, 500);
      }
    } catch (IlluminateDatabaseQueryException $ex) {
      $res['status'] = false;
      $res['message'] = $ex->getMessage();
      return response($res, 500);
    }
  }

StockEvent

<?php

namespace AppEvents;

use AppProduct;
use IlluminateContractsBroadcastingShouldBroadcastNow;


class Stock extends Event implements ShouldBroadcastNow
{
   
    private $product;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Product $product)
    {
        $this->product = $product;
    }
    public function  broadcastOn()
    {

        return  ['move.qte.stock' . $this->product->id];
    }
    public function broadcastWith()
    {
        return ['qte' => $this->product->qteenstock];
    }
}

why brodcast cancel deleting from database

Source: Laravel

Leave a Reply