2. Laravel Activity Log By Team Spatie - Model Events

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when you want to log or record the activity of user or activity of any model on the level you need to have this package called a lateral activity log created by the spazzy team and in the last episode we have seen that how we can install setup with this package also we have seen that how we can use the straight on the user model to grab or to record every kind of event happened on this model so we have just added this trait on this user model you can see the straight and with the help of tinker we have created a user on our database and that user reflects the activity and that activity is logged on our activity log table on that database and you can see here we have but what if I want to update this user so again let's use a stinker so I will say user is equal to and I'm sure the user is created with the ID of one so I will grab that and what we need to we need to give the double colon and then what I will say user update and I am now updating the mean and I'm updating the name with bit fumes so let's see what going to happen so I update it says true that means the name is updated and yes it is updated on the database and one more entry is created third one with the idea of nine and it says the app user model is updated you can also grab the last one so you have this activity all then you can simply say grab me the last one and now we have the last one so updated but what about that Lee part so yes I can firstly create one more user so let's use this Factory to create one more and let's say user find with the idea of two and delete it so [Music] like this so you can see now we have the to user on our database with the idea of three actually because I was testing before that so that's why ID is increased okay so if I hit enter it says true that means the user is deleted and one more activity is added there which is called deleted and this means and now you can have all the activities like creating deleting updating any kind of event is now crapped but what about update and what about the changes we have done on the update so once more I'm changing it to sarthak the name of first user to Salta it is true and we know that the event is logged but we don't have the information of what is updated so to know about that you have to go to the documentation for now you can see it says protected static log attribute to name and text you need to provide this and now copy from there and on this user model I have just pasted so what I'm saying actually to our model is that I want to log attribute and I want to log information about name and email so whenever there is a change in name and email yes log with the detail about that property so now I will after adding this I will quit from the tinker once more go inside the tinker and then grab the first user and then after that and now I'm going to update that user in two bedrooms so again changing the name from sort of tooth becomes hit enter it says true that means the user is now did it if i refresh this page the thirteenth log on our activity is saying updated for app user but also having the information about all the fields I have described on this model so it now recorded the field before updating and after updating that says old was new is bit films so this is very very useful so in this way you can you can know that in real information about what is actually changed on the model also you can have the same effect on the delete so if I create let's say create one more user like this and with the ID of four okay so I will going to delete firstly I will find with the idea for and then I will delete so before deleting you can see because they have created user so it says user is created with a a name and email so that's cool and if I delete that refresh this page that event is also added it says user is deleted with these attributes you can also customize the event being logged and by adding this field and just say I just want to record event for created I don't want for updated I don't want for delete so again go to tinker and I'm going to create a user so I have created user with the ID of 6 this means I have a new activity called app model is created good but what if I want to say user find with the idea of 6 and delete it yes I have deleted it says yeah it is true that means users deleted but you can see we don't have any log for the delete similarly if I grab a user with the idea of 1 and update it update with name of once again let's say ABCD and anything actually so after updating it says true but again we don't have any log what if I just add this event also and whenever you make changes in any model you need to go out of tinker and just go once more and then I'm going to update the and this means now it will have a new head interlock for update before that it was not logging for update but now it is logging for update also so these are the things you have seen that how you can customize the event you can add the details of the fields on this activity log model in the next episode we will go beyond these things and see other things like description and log name and different other things for this package so if you liked this episode give it a thumbs up comment your views about this level activity package and what you think about this package go and follow bit tombs on Facebook Twitter Instagram LinkedIn you can also follow me on these platforms at Celtic savvy and follow spicy is Pasadena and this package we will meet in the next episode till then good bye
Info
Channel: Bitfumes
Views: 46,383
Rating: undefined out of 5
Keywords: laravel activity log, laravel activity log tutorial, laravel activity logger, log activity laravel, activity log laravel example, laravel activity log spatie, laravel log user activity, laravel activity log example, spatie packages, spatie package in laravel, spatie laravel permission package tutorial, spatie laravel media library, spatie freek
Id: j6FB5WelWZY
Channel Id: undefined
Length: 7min 32sec (452 seconds)
Published: Tue Jan 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.