Display Bilingual:

Hello guys, today I want to show you 00:00
quickly a few examples of livewire in 00:01
action. So yesterday on this channel 00:04
I've shown t-shirt project with activity 00:06
log but some of that project was based 00:10
on livewire and I will show you two 00:12
cases. For example, if you choose a 00:14
color of a t-shirt, as you can see the 00:17
sizes are refreshed automatically. I 00:19
choose red t-shirt and then it shows and 00:22
disables the options that are out of 00:25
stock. So this is powered by livewire 00:28
component on that specific side of the 00:30
page. And also second function I will 00:33
show you is actually adding to the cart. 00:35
So whenever I click this cart one is 00:38
updated on top with the number being 00:41
refreshed automatically without 00:44
refreshing the full page which is again 00:46
live wire component with events. Let me 00:49
show you the code. So the page of 00:52
showing the product is a typical Laravel 00:54
blade. No live wire here. So we have 00:56
show blade with full HTML in this case 00:58
and inside of that blade we have live 01:01
wire as a separate part of that page. So 01:04
this is how I typically use livewire in 01:07
general. This is my personal preference. 01:10
I don't use livewire as architectural 01:12
decision for all the routes replacing 01:14
laral controllers but instead I use it 01:17
only for small specific portions where I 01:19
do need dynamic elements. Let's take a 01:23
look inside. So that product selection 01:25
livewire component consists as every 01:28
livewire component from blade and then 01:30
class of data and logic. If we took a 01:33
look at blade so you would understand 01:36
the first visual logic. We have a form 01:38
wire submit add to cart and we have 01:41
hidden values of product ID color and 01:43
size coming from livewire component. 01:46
We'll get to that in a minute. And then 01:48
if we have colors then we have for each 01:50
of colors we show those divs and inputs 01:52
and we have radio with value with wire 01:56
model live and live is important in this 01:59
case. So this is one for each for 02:03
showing this part of the page the 02:05
colors. Then we have another for each. 02:08
If we have sizes then for each the sizes 02:11
similar thing we show the labels and 02:14
inputs with wire model with value of 02:17
each size and then submit button is 02:20
active only if we have colors and sizes 02:23
and if we have both selected then we und 02:26
disable that button. So that's the 02:29
visual logic. Now the product selection 02:32
as a component on mount we have the 02:34
product from the database and then the 02:37
default values of selected color and 02:39
size are null by default and then we 02:42
have get available colors property get 02:44
available sizes property where we get 02:47
the data from the database get all 02:50
colors get all sizes and then the main 02:52
so to speak magic of updating sizes for 02:55
colors happens on updated. Let me find 02:58
it somewhere. Yep, this one. Updated 03:03
selected color ID. We reset the selected 03:06
size ID to null. And then in the blade, 03:09
we have for each of all sizes, but 03:13
inside we use is size available, which 03:16
is another method in the same component. 03:20
Is size available, which works with the 03:23
collection of available sizes. I'm kind 03:26
of jumping up and down the code, but I 03:29
hope you get the idea. The dynamic thing 03:31
is about updating the selected color ID 03:33
and then refreshing the sizes. And then 03:36
as a result, the submit of that is add 03:38
to cart. This is where we add cart 03:41
product. This is where we log the 03:44
activity which I mentioned in the 03:46
previous video on this channel. And this 03:48
is the second thing I want to show cart 03:50
updated dispatch event. From this point 03:54
of view, from this livewire component, 03:56
we're dispatching the event to anyone 03:58
who wants to listen to that event. It 04:01
may be any livewire component anywhere 04:03
on the page. And in this case on this 04:06
page, we have header navigation blade 04:09
component. And inside of that, we have 04:11
another livewire component, small 04:13
component for the card link I've showed 04:16
you on the top right. So again, liveware 04:18
use case only for small interactions for 04:21
specific parts of the page. Inside 04:24
nothing really fancy link to cart with 04:27
card count as variable and that card 04:29
count comes from card counter logic of 04:33
livewire component by default zero and 04:37
by default we update cart count checking 04:40
that from the database from users 04:43
current and products. But then the main 04:45
thing is the PHP attribute on with the 04:48
event name. The same event name which is 04:50
called from that product selection 04:54
component. This dispatch the name is get 04:56
called in on PHP attribute and then 05:00
update card count is called again 05:03
refreshing the card count and then 05:06
rerendering this card with the updated 05:08
value. So yeah, two quick examples of 05:12
LiveWire. For those of you who haven't 05:14
used LiveWire, it may be an example of 05:16
where you could use it and how exactly 05:19
it works. If you want the full source 05:21
code, it's available on Laravel Daily 05:23
Comm in project example section. I've 05:25
published it here. T-shirt eshop with 05:28
LiveWire and also activity log kind of 05:30
twoinone project. So I will link that in 05:33
the description below. What do you think 05:35
about this LiveWire example? Would you 05:37
have done something differently or would 05:38
you have done it without LiveWire? Maybe 05:40
you prefer Vue.js or React or something 05:42
else. Let's discuss all of that in the 05:45
comments below. 05:47

– English Lyrics

🕺 Listening to "" and picking up vocab? Open the app and learn it while it’s hot!
By
Viewed
1,468
Language
Learn this song

Lyrics & Translation

[English]
Hello guys, today I want to show you
quickly a few examples of livewire in
action. So yesterday on this channel
I've shown t-shirt project with activity
log but some of that project was based
on livewire and I will show you two
cases. For example, if you choose a
color of a t-shirt, as you can see the
sizes are refreshed automatically. I
choose red t-shirt and then it shows and
disables the options that are out of
stock. So this is powered by livewire
component on that specific side of the
page. And also second function I will
show you is actually adding to the cart.
So whenever I click this cart one is
updated on top with the number being
refreshed automatically without
refreshing the full page which is again
live wire component with events. Let me
show you the code. So the page of
showing the product is a typical Laravel
blade. No live wire here. So we have
show blade with full HTML in this case
and inside of that blade we have live
wire as a separate part of that page. So
this is how I typically use livewire in
general. This is my personal preference.
I don't use livewire as architectural
decision for all the routes replacing
laral controllers but instead I use it
only for small specific portions where I
do need dynamic elements. Let's take a
look inside. So that product selection
livewire component consists as every
livewire component from blade and then
class of data and logic. If we took a
look at blade so you would understand
the first visual logic. We have a form
wire submit add to cart and we have
hidden values of product ID color and
size coming from livewire component.
We'll get to that in a minute. And then
if we have colors then we have for each
of colors we show those divs and inputs
and we have radio with value with wire
model live and live is important in this
case. So this is one for each for
showing this part of the page the
colors. Then we have another for each.
If we have sizes then for each the sizes
similar thing we show the labels and
inputs with wire model with value of
each size and then submit button is
active only if we have colors and sizes
and if we have both selected then we und
disable that button. So that's the
visual logic. Now the product selection
as a component on mount we have the
product from the database and then the
default values of selected color and
size are null by default and then we
have get available colors property get
available sizes property where we get
the data from the database get all
colors get all sizes and then the main
so to speak magic of updating sizes for
colors happens on updated. Let me find
it somewhere. Yep, this one. Updated
selected color ID. We reset the selected
size ID to null. And then in the blade,
we have for each of all sizes, but
inside we use is size available, which
is another method in the same component.
Is size available, which works with the
collection of available sizes. I'm kind
of jumping up and down the code, but I
hope you get the idea. The dynamic thing
is about updating the selected color ID
and then refreshing the sizes. And then
as a result, the submit of that is add
to cart. This is where we add cart
product. This is where we log the
activity which I mentioned in the
previous video on this channel. And this
is the second thing I want to show cart
updated dispatch event. From this point
of view, from this livewire component,
we're dispatching the event to anyone
who wants to listen to that event. It
may be any livewire component anywhere
on the page. And in this case on this
page, we have header navigation blade
component. And inside of that, we have
another livewire component, small
component for the card link I've showed
you on the top right. So again, liveware
use case only for small interactions for
specific parts of the page. Inside
nothing really fancy link to cart with
card count as variable and that card
count comes from card counter logic of
livewire component by default zero and
by default we update cart count checking
that from the database from users
current and products. But then the main
thing is the PHP attribute on with the
event name. The same event name which is
called from that product selection
component. This dispatch the name is get
called in on PHP attribute and then
update card count is called again
refreshing the card count and then
rerendering this card with the updated
value. So yeah, two quick examples of
LiveWire. For those of you who haven't
used LiveWire, it may be an example of
where you could use it and how exactly
it works. If you want the full source
code, it's available on Laravel Daily
Comm in project example section. I've
published it here. T-shirt eshop with
LiveWire and also activity log kind of
twoinone project. So I will link that in
the description below. What do you think
about this LiveWire example? Would you
have done something differently or would
you have done it without LiveWire? Maybe
you prefer Vue.js or React or something
else. Let's discuss all of that in the
comments below.

Key Vocabulary

Coming Soon!

We're updating this section. Stay tuned!

Key Grammar Structures

Coming Soon!

We're updating this section. Stay tuned!

Related Songs