This episode is for members only

Sign up to access "Laravel Mentions" right now.

Get started
Already a member? Sign in to continue
Playing
08. Sending mention notifications

Transcript

00:00
We're going to be sending mentioned notifications by email so I've got some local email testing software up and running. Whatever you decide to use to send email it doesn't really matter or if you're not sending notifications or if you're storing notifications in your database of course
00:15
you're not going to need to do this. I'm just going to go over and configure my application to send emails with hello which is the software that I prefer so I just need to switch the port here to 2526 so let's go over to emv and let's go down to our mail section and switch that to 2526 and we should be good to send emails now. So we want to go ahead and create out a notification so let's
00:39
go ahead and do that first of all so let's say make notification and we're going to call this comment mentioned so every time someone gets mentioned for the first time in a comment we're going to send this out. So what do we do here? Well we want to go ahead and say user find and remember we get them pivot ids so these are all of the user ids that have been attached
01:00
then what we can do is do a higher level each on this and say notify so that will just notify each of them users that have been found and that's going to be a new comment mentioned that thing that we just generated and we can pass through the model which is the comment itself so remember this is going to be the actual comment so we can extract any information out of this that we need.
01:22
Okay so now that we've got that let's open up comment mentioned and let's bring in the comment here that we're passing through and set that as a protected or public proxy whatever you want to do. We'll change over via or we can change over via you can say mail, database, sms, slack, anything that is supported by laravel notifications but I'm just going to be using
01:48
the mail option just for now and now we've got two mails so let's just go ahead and customize this and make this read a little bit better. So what I'm going to say here you were mentioned in a comment by x that's going to be the user who mentioned us so that's just going to be the author of the comment so we're just going to say this comment user a name or username whatever you
02:15
want to say we can get rid of this last line here and let's just add in an action so let's go through to view the comment that we're just looking at so to do this what we want to do is and this isn't really that important but it does link it up into the system as a whole what we want to do is we want to generate a url with a fragment here so to do this we can actually use the new uri helper
02:42
and we can say from the root so that will be the comments index comments dot index and let's just make sure yeah it's comments dot index then from here what we can do is say with fragment and we can add in a fragment like comment hyphen and then the comment id what that will allow us to do is build up a url without having to concatenate manually with php onto the end so let's say
03:08
comment and id now once we've sent this we'll check what this actually does so if you've not seen this uri helper before in laravel you'll see what it does and we should be good and of course you could fill in to array if you're storing these in the database as well okay let's go and mention someone and see what happens so let's say hey tabby and let's hit post and let's go over to
03:33
hello and see what we've got in our inbox here yeah sure enough we've got a comment mentioned here you were mentioned in a comment by alex and if we click view comment you can see that that has constructed the url through to the overall comment index but it's added the fragment onto the end there so what we can do very quickly and again this isn't completely necessary is
03:54
over in each of our comment items we can go ahead and add in an id for each of these so it's going to be comment hyphen and then the comment id and that means that when the user goes through to this page like this they should be taken directly to the comment so if we head back over to hello and click view comment we're now taken down to that comment that they were
04:15
mentioned in not important to what we're building but of course that helps if you want to include that in what you are using this for okay great so we are now sending these notifications to users who have been mentioned of course it would make sense to go ahead and test this functionality so let's do that in the next episode
15 episodes1 hr 52 mins

Overview

Add mentionable functionality to your Laravel applications and mention users, projects, issues… literally anything.

We’ll start by setting up a simple comment system with Livewire, then detect, sync, notify and test mentions step-by-step. Not using Livewire? Don’t worry, the core functionality works with any stack.

If you are using Alpine/Livewire, we’ll add mention support to textareas to get a list of users we’re able to mention when we hit a trigger key.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!