Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
pusher pass parameter in laravel broadcastAs

hi i have this js code

    var pusher = new Pusher('my pusher key', {
        cluster: 'ap2'
    });
    var channel = pusher.subscribe('my-channel');

    channel.bind('my-event', function(data)
    {
        console.log(data);
    });

and this is my laravel code

protected $pos_invoice;
public function __construct($pos_invoice)
{
    $this->pos_invoice = $pos_invoice;
}
public function broadcastOn()
{
    return new Channel('my-channel');
}

public function broadcastAs()
{
    return 'my-event';
}

and this is the call code

return event( new \App\Events\New_pos_online_order_event('aa'));

now the code

    channel.bind('my-event', function(data)
    {
        console.log(data);
    });

always return [] on console so i tried this

public function broadcastAs()
{
    return 'my-event.'.$this->pos_invoice;
}

and this

public function broadcastOn()
{
    return new Channel('my-channel'.'asdfasdf');
}

when i change anything on

public function broadcastOn()
{
    return 'my-channel';
}

public function broadcastAs()
{
    return 'my-event';
}

the code not working and not returning anything on console so how can i pass parameter on pusher and laravel with js thanks ..

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to define the function broadcastWith

**
 * Get the data to broadcast.
 *
 * @return array
 */
public function broadcastWith()
{
    return ['pos_invoice' => $this->pos_invoice];
}

You will receive the array in the data of the bind function

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda