Refreshing a Laravel Livewire component from another component using emit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so i'm on the edit page of this theme and one slight annoyance thing about it is in the top corner we've got the username so in this case it's showing dave and we've got david down here but then if i just change the name down here and then update it tells me that it's updated but up there it still shows me the old name and it says like that until i refresh the page i want to refresh then we can see it so that's one thing i'd like to change is actually changed they changed this little menu into just a bit but a little simple lightweight component that can refresh when this is updated and that way when you change somewhere here it can refresh up there so let's go and we're doing that so now i need to create a live wire component so i can say where our traffic is and i'm just going to create one called user menu so then if i look into resources views livewire or the user hyphen menu and then if we're going to layout an app and this is where the where the menu is is entire drop down so i can literally just cut it from here and paste this in don't need to change anything here because all i want to do is it to refresh i can close that down now and then here i can say lab wire and then say use that menu i want it to load up so now if i've done it very rightly we shouldn't notice any difference on the page that it still works even though it's loading from our liveway component now instead okay brilliant so next we need to open up the actual labview component itself uh what i need to do is to actually put a listener on on this so what will happen when is an event file is this listener can run richard refresh itself so i'll create a protected listener and then within the listener it just takes two properties the actual name of the event so i'm going to call it refresh use that menu and then when that's run i want it to fire and refresh okay so that'll fire off the refresh and then on the when the edit profile runs what i want to do on here is i want to fire off that event so i'm going to say email and then when i say refresh user menu so when this is updated this whole event will get fired and then this event will see that's been fired and refresh yourself okay so come back refresh the page so now if we change the name click up there now updates straight away i've always have to refresh the page manually which is much better and that way it just feels a little much more natural and that you get the immediate feedback that you know it definitely has changed
Info
Channel: David Carr
Views: 485
Rating: undefined out of 5
Keywords: Laravel, Laravel Livewire, emit
Id: C3FIsdzCR2A
Channel Id: undefined
Length: 3min 48sec (228 seconds)
Published: Sun May 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.