The next thing we are going to do is define an event, that is, dispatch an event similar to what we already did with the car event that we have here, dispatch an event with the parameter When we do any of the CRUD type operations of delete, update or create, so then we are going to listen to this from here and we are going to show the toas, that is the meaning, so if you have the same problem as me, at least for the moment, please comment on this. We will resolve this in the following classes and do the final details so that it does not give you an error there, which is a section that appears to me, so okay, let's go there.
I'm going to start from here to define the events that obviously can have any name, so I'm going to place it here, for example, after the session I'm going to place a dispatch and you put the name of the event that in this case would be item delete, you can put car item delete whatever you want, again since the application has a limited scope and is not going to do so many things, I put here in a generic way item, it can also be product if you feel comfortable and something similar, here this is the update, so I put update here and we pass the parameters that in this case would be the post, let's see where I have it here I have it in the variable, I can put comma post here the same but this would be to create:
app/Http/Livewire/Shop/CartItem.php
public function add($post, $count = 1)
{
//***
// eliminar
if ($count <= 0) {
if (Arr::exists($cart, $post['id'])) {
//***
$this->dispatch("itemDelete");
}
return;
}
// agregar
if (Arr::exists($cart, $post['id'])) {
$cart[$post['id']][1] = $count;
$this->dispatch("itemChange",$post);
} else {
$cart[$post["id"]] = [$post, $count];
$this->dispatch("itemAdd",$post);
}
//***
}
To learn how to use events, you can consult:
https://www.desarrollolibre.net/blog/laravel/plugin-de-mensajes-toast-en-laravel-livewire
- Andrés Cruz
Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter
I agree to receive announcements of interest about this Blog.
!Courses from!
4$
In Academy
View courses!Books from!
1$
See the books