Thanks to visit codestin.com
Credit goes to github.com

Skip to content

useEcho hooks do not define `X-Socket-ID' on inertia requests #447

@TimKunze96

Description

@TimKunze96

Echo Version

2.1.6

Laravel Version

12.16

PHP Version

8.4

NPM Version

10.9.2

Database Driver & Version

MySQL

Description

In order to make use of laravels ->toOthers() broadcasting filter it is necessary to include the Socket-ID in each request sent by inertia. See docs.

The current implementation of the hook does not seem to do this, so the filtering will not work properly.

A workaround for this issue is to manually set the header before an inertia request is sent:

import { echo } from '@laravel/echo-vue';

router.on('before', (event) => {
    const id = echo().socketId();
    if (!id) return;
    event.detail.visit.headers['X-Socket-ID'] = id;
});

Steps To Reproduce

Setup a laravel application with broadcasting, dispatch an event via inertia request with ->toOthers() and observe the missing X-Socket-ID header in the inertia request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions