How to use Laravel WebSocket - This lesson private channel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my friend today i'm gonna teach you how to use laravel website specifically i'm gonna teach you how to use private channel private channel is a channel that you can send your notification to a specific user that is authorized and other user not seeing this private channel so let's start to implement this and that would be fun there are some tips and tricks so let's go to install a laravel 8 authentications package because it needs to authenticate user its private channel so the package name is composer require laravel freeze let me tell you uh if you didn't watch the last video about laravel website on a public channel the link is the below and you could watch that to set up your environment install dependencies and packages for web circuit in this lesson actually we're going to use the last platform that we created so let's go to continue this so we installed this and let's migrate to create our tables user tables specifically we need to generate some roads and views for authentication thanks to the open source community actually you can use this command to do this all the stuff for us freeze install so let's install node modules and build the js files to have the client section have as you can see it's done so let's create an event to send notification to user so let's go to the events folder into order shipment and change this channel name to something that we want and i'm gonna say this order and put an argument here this user id so i'm gonna add this user id in top of here and also put public string public message attribute and i'm gonna get this message and user id from the constructor so user id and message and let's initialized this properties well oops that's working actually so as you can see this user id is for channel i'm gonna override the method to change the even default event name for the client section and broadcast as return to something like order dot shipments and let's go to the top of this shipment event and he implements should broadcast interface so let's go to the roads folder and into the so let's go to the roads folder in the channels.php and create a road to authorize user to access to this private channel i'm gonna channel and this channel name must be exactly the same that we have in here so i'm gonna copy and paste this in here so so just delete this keyboard from here that's is enough and let's create a callback for that so the first argument is actually the user this user fill out with the session and this user id is calling by the road and return and user dot id is equal equal to int user [Music] id so if any user wants to access to this private channel they should pass from this broadcast channel that we created right now that would be authorized so let's go to the web.php file to create a road for firing and even to send notification to user order function even new perfume [Music] shipment event the first one is user id so i'm gonna just type one because the first user id is number one and i'm gonna tell fire this event for user one and user of course user number two can't access to this so in your program you should change to whatever you want or don't forget to go into this file app.php and uncomment this broadcasting service provider this service provider actually creates a road to authenticate user and also set up broadcasting so let's go to the client section and create a subscriber to our event and fire and show messages to the user so let's go to this resources folder views and welcome i'm gonna create an script tag in here put it echo private to the order dot i'm gonna use blade template engine in here to get the idea of the user that is actually authenticated and uh listen to dots holder shipment so let's go to this page and see what would happen just do not forget to import script cersei asset change it must be work right now so let's go to check what do we have in here serve seven days and serve our website server so let's register a user to authenticate it for this channel i'm gonna write my name something dummy let's go to the first page to the dashboard section and see the console log and check what what do we have in this here onto the networks and ws as you can see subscribation is completed so let's fire an even to see what we will get on the console so as you can see hey your order shipped and we can refresh it and check it let's go to create a new tab and to incognito mode and check we get the same result here or not because our user is i didn't plug them in here so in the console of course we're getting for all three errors as you can see it's just in here let's log in in this page and see what do we have in here it was yeah something like that of course this is not my gmail let's go to this first page and see what we get hey we get the notification on thanks for watching this video in the next video i'm going to teach you how to use laravel websocket i mean private web circuit private channel when you are using authentication with tokens and not in the session mode it's a bit tricky but that is fun you would enjoy it and i'm gonna tell you more about how you can change the authentication endpoint and other stuff for private channel see you thank you for watching my video please subscribe if you don't subscribe thank you so much
Info
Channel: Programming by Ali
Views: 5,142
Rating: undefined out of 5
Keywords:
Id: 5uVAJ250Wgw
Channel Id: undefined
Length: 13min 14sec (794 seconds)
Published: Fri Aug 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.