Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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


2. 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,
});


3. 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:


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


5. Replace 'channel-name' and 'EventName' with your actual channel and event names, respectively.


Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(