Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Laravel websockets


Dear Team i am using laravel version 8.1.7, i could not figure out the bootstrap file where i need to enabled

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
broadcaster: 'pusher',
key: 'mykey',
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
});

kindly guide


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)

Hi,

To enable the Laravel Echo with Pusher in your Laravel project, you need to follow these steps:

  1. Install Pusher and Laravel Echo using NPM:
npm install --save pusher-js laravel-echo
  1. Configure the Laravel Echo by adding the following code in your resources/js/bootstrap.js file:
import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
 broadcaster: 'pusher',
 key: 'mykey',
 wsHost: window.location.hostname,
 wsPort: 6001,
 forceTLS: false,
 disableStats: true,
});
  1. Make sure to replace mykey with your actual Pusher API key.

Make sure to include the bootstrap.js file in your webpack.mix.js file:

mix.js('resources/js/bootstrap.js', 'public/js');
You can then use Laravel Echo in your Vue components or JavaScript files as follows:
  1. You can then use Laravel Echo in your Vue components or JavaScript files as follows:
Echo.channel('channel-name')
 .listen('EventName', (data) => {
 console.log(data);
 });
  1. Replace 'channel-name' and 'EventName' with your actual channel and event names, respectively.

Thanks

Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(