hello friends and welcome to bitfumes in this episode we are going to work on
the notification system in level so for that you have to go to lateral Docs and
just search for notifications and here we have notifications and in the intro
part you will get the intro of the notification but let's get on the work
directly so what we have to do we have to create a new project for our
notification system so let's just create that project so let's open terminal here
and I'm on terminals let's say laravel new notification and it will create a new
project obviously you know that so wait for this it is completed select start
server so PHP artisan but before PHP artisan we have to go into this directory
so notifications CD and then PHP artisan so and it's started the server so let's
say notification no not notification localhost:8000
the notification is sent to user so obviously we need a user and migration
will help us here so let's create a new terminal here and now I will say PHP
artisan migrate I have to migrate creating tables because we have created
the project so let's open this project in our sublime
so sublime is here and if I go to this database then migration then you can see
level gives out-of-the-box to migration so for password reset and user table so
we need user table that's very nice so let's create that but before that we
have to configure our .env file to connect to database so let's just
connect to database let's say notify the database name then it will be root and
password is nothing that's good so let's go to sequel pro and
new database called notified notify is good then it is created let's go to
terminal and just hit enter PHP artisan migrate and yes
it is now successfully migrated so we had this user here that's nice we have
to create a user or register a user so next task is to create PHP artisan
make auth and it will create authentication scaffolding so let's go
to chrome and if i refresh you will see login and register button right here so
let's register ourself so sark and details are already filled so let's give
password 1 2 3 4 5 6 and we are successfully registered but we have to
restart our server as my always problem is this so let's just restart it so once
more that's nice and if I give it a refresh and boom everything is correctly
working that's great this means we must have a user that's good so obviously if
you are working on a notification so we have to create a notification new
notification is created by this command make notification so let's just copy
this notification good terminal on this step and just paste this end
notification name let's say task the complete simple completed task completed
or complete that doesn't matter okay so it is good and notification is created
but real this notification stay in our level project so if I go to sublime go
to app folder here we have new folder notifications and our task completed
notification is here so you can see it is extending this notification class and
it can use a trait of queuable that means if I want or we want to make this
queue able because the notification can be mailed it can be
data based also and there are other options but if you are using email then
email takes time and obviously we will cover this queue system so let's just
complete this tool you don't have to do anything else
notification is completely set up on your system so let's see what the next
task we have - so to send a notification we have to use this thing so let's just
go to again sublime I will go to web dot PHP file and here
this instead of returning this view what I am going to say I am going to firstly
get the user so user find with the idea of one obviously ID will be one then I
will say notify then inside this new task completed
okay that's it you don't have to do anything just import these things at the
top so I am using PHP companion so that's why I have to use this I will say
use don't use only so that's good so you can see it's not doing that thing
because my notification name is tast not tasks so let's just make it correct so
rename this one so that's last completed that's nice
and now let's import this at the top so which is here obviously the user model
import it at the top so here we have so everything is setup so let's just go to
Chrome and go to home page it will try to send email it will fail because we
have not set up our email configuration so if I open dot ini' file you can see
my email configuration there is that yeah email configuration is not set up
so let's just go to mail trap mail trap that should be trap
yeah mailtrip.io it's very it's very good website because it can trap all the
email so you can just test it literally the email sent from your project so
that's good so let's just grab these credentials and don't try to copy these
financials because I will change it later after this episode so let's go
password that's nice and it doesn't matter we can say TLS or not that's good
mail trap is set up so obviously as usual we have to restart our server so
server is restarted so let's go to Chrome once more and refresh this page
and let's just wait for some time it will try to send email to our mail trap
and it is successfully done so if I go to mail trap we have task completed
email and whatever you can give on this email will reflect here so where this is
configurable so if I go to task complete notification you can see via email we
want to send it by email and to mail that means what we are going to email
email this thing's so if I change this it's like
bitfumes that should be bit fumes yeah bitfumes and now go to Chrome reload
this and we must see a new email with the button saying BitFumes so here we
have the new one and yes Bitfumes is here
one thing more if you go to this documentation you can also send this
notification but by using this facade we are using here the simple function but
we can you also use facade so let's just grab this and go here instead of this
all these things let's just paste it and I don't want to pass anything then my
task completed and no yeah the user so let's just say user users is equal to
user::find(1) with the idea of one and this system this notification of
notification is sending well facade is useful when you want to send to multiple
users that you can see its users not user that's good and let's go here
refresh this page and we are expecting new email on our mail trap inbox and yes
we are having this and you can see exactly the same but very useful so this
is all about notification not all about in the next episode we will see more
depth concepts of notification so till then don't forget to subscribe and if
you have any problem feel free to message me comment me you can also
message me on Facebook Twitter and Instagram so we will meet in the next
episode till then good bye