Laravel Package Development Series - Intro

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey guys, welcome to LaraTips. Three days ago i added a poll and i asked you guys do you want me to make some tutorial about how to make a package then within the span of three days 163 of you voted and among them 93 percent of you want me to make laravel package tutorial. So thank you very much guys for participating in this poll. I was only expecting about 100 votes but I got about 163 votes within just three days. So thank you very much for your participation and in today's video, we'll be looking at the overview of what package we are going to develop and from the next video we'll start developing it. So this was the screenshot of the tweet that was posted by Aidan Casey and i don't know if i correctly pronounced his name or not but i was inspired from this tweet and i'll be making this feature into a package. Basically what he has shown here is that we  must make sure that we need  to send the notification if a password is changed. We'll be doing the same thing but we'll be converting this into a package and we'll publish it into the composer. So without any delay let's get started. Let me show you how the package will look like. So here i have already installed the package. Currently it is in my local machine but we can also install the local packages and i'll also show you how to do that and if i show you here in the composer.json file. So here is the package, password change notification and in the user model i am just implementing this password change contract and using this password change trait. And after adding this whenever we change the  password, it will automatically  notify the user. Here in the browser i have also opened this mail trap where we can trap the mails that we have sent from our local machine. Now here let me open the tinker like this and now i'll change the password from here. I'll find the user with the id of 10. Here you can see it over here and i'll write the password as apple and i'll save it now. So since i have changed the password and saved  the user model then the  email will be automatically sent, like this, and by default the package will assume that you have email column and password column in the users table or in whichever table that you want to use it but you can change that as well. So let me show you how to do that. So here in the users model you can see here we are using this password change trait and you can see here i have these two methods password column name and email column name you can just copy these come here and just paste it over here and let's say you have the column name as user_email, then you can just override it like this and let's say you have different name for the password column then also you can change it from here but it's email and password for me so i don't have to do this. And also you saw that whenever i was sending the email it took a little while to send the email because by default i am not adding this mail to the queue but you can modify that as well you can see the method over here, should queue password change mail. So i'll just copy this and paste it over here and instead of false we'll write true like this and here let me restart the tinker and i'll find the user with the id of 10 and i'll change the password to apple2 and i'll again save it. Now it's so fast and if i come here and show you there is no mail that has been received but if i just open a new tab over here and i'll say php artisan queue:listen like this then it is now processing that email which means that it is successfully added to the queue and it is processed as well and you can see here the email has arrived as well and the email is same as that we have seen before. Not only this but you can change this whole email as well. Let's say you want to make your own email view and send it to the user then you can also create a custom mail as well. Now i'll show you how to do that as well so here i'll stop this queue and i'll just remove this as well and let me remove this one and here we'll say php artisan make:mail SendPasswordChangeEmail and the markdown file will be emails.email_changed. Whenever we do this it will automatically create a view file for us. So i'll just hit enter over here. It will create mail php file and email_send blade file. So here are these two files. It is not visible here but if i just click here and show you so here is the email file and this emails, inside the emails we have this email changed. So i'll just write here custom mail like this and in the change email password we don't have to do anything we just have to keep it as it is. Now in the user model again if i just show you inside this password change trait, then here we have this function. I'll just copy it and paste it over here and instead of returning this new password change mail will return whatever we have just made which is send password changed email like this and let me import this mailable as well which is this illuminate mail mailable and whatever i have imported you can all see here. Now let's again change the password and see what the mail will be. So here let me open the tinker and here again i'll find a user with id of 10 and i'll change the password and again save. The mail is successfully sent and now in the browser you can see here this is the custom mail and it is coming from the custom blade file that we have made so it is gonna  be very very customizable  and we will be writing tests as well. So that's it for this video guys and from the next video we'll be looking at how to develop this package So thank you for watching, have a great day. Bye.
Info
Channel: Laratips
Views: 511
Rating: undefined out of 5
Keywords: laravel, laravel package development, package development in laravel, package, composer, packagist, laravel advanced, send mail, password changed, send mail when password changes
Id: D9GeqOpOTp0
Channel Id: undefined
Length: 6min 13sec (373 seconds)
Published: Thu Dec 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.