YouTubevideo· Apr 26, 2025· 13:24· 1,700 views on YouTube

Keep Your Users Content in Check with this Laravel Package

Watch on YouTube ↗
0:00

React at a moment you like. The best moments light up here.

transcript

32 moments
  1. So, real quick, here's a neat little package that I found. So, let me introduce you to Squeaky, a Laravel validation rule package that helps catch profanities. That way, you don't have any more of those pesky little and but this is powered by profanity under the hood, which is a a pest PHP plugin that helps catch profanity in your applications. seen uh some bits and pieces of people that have used it.

  2. But the neat thing is that now this powers this particular package and you can just use it within your controller or since I'm using LiveWire, I can just use it in LiveWire and it basically just cleans those um those pesky, you know, naughty words. So that way you don't have the uh profanity that you might not want within your application or at least in particular fields.

  3. Maybe this is being used just to make sure that you don't have any like spam or naughty characters who are trying to log in or create application or create users in your application. Or maybe it is specifically for like a chat application where you don't want a particular message to contain any kind of profanity. So how do we use it? Let's go ahead and dive into some code just to make sure see what's up. How does it work and how might you want to use something like squeaky to keep make sure that your application is squeaky clean.

  4. All right, I have a brand new Livewire application scaffolded out.

  5. This is basically just using the Livewire starter kit, the brand new one, and I'm just going to compose require John Pervvis squeaky and we should be able to get up and running. And we should just be able to have to pass in to any validation rule that we have to say, "Hey, make sure this is squeaky clean." I'm not going to use the uh beeper anymore just for your your ears, the sake of your your listening fatigue if if you will. But let's go ahead and open up our code editor.

  6. I've actually been using zed more and more recently, especially with light mode. I just like how fast it is, how how quick it is, and just how clean it looks. Um, but that doesn't mean I'm done with VS Code, especially any VS Code forks as well, but I'm just trying it out. So, for those in the comments, yes, this is Zed. All right, why don't we start in our dashboard? And basically, I just want to create something right here. We're just going to create a new live wire.

  7. Probably let's just call it uh squeaky. We'll call it squeaky. and we'll go ahead and add that there. And I'll just say PHP artisan makevault. And we'll call this squeaky. So, we should have a new vault component at squeaky. Um, and then I'll go ahead and bring that up.

  8. And so, in here, I basically just want to have a quick little insert um probably like an inserted just a a quick little form to say like, hey, let's let's create a a chat message. We'll pretend that we're saving this to the database right now. We're just going to display it on the page. So I'm just going to say there's a public function uh a public string of message and we'll just go ahead and declare this as blank.

  9. And so we'll also say like public function send message and we'll pretend like this is being you know sent out to other people. It's being dispatched. But for now we'll just say we we'll have a a display message as well. So that way display me message is blank. And in here we'll set the display message to this message. So that way in here we'll just say flux input. We'll wire model that to message. And then we'll uh we'll probably have a button. We'll say flux button wireclick send message.

  10. Actually, we'll probably just say type equals submit. And then we'll set this up in a form so we can have that little nicity right there. And there we go. So, we'll say wire submit equals send message. Sounds good. All right. And then we'll just go ahead and display out that display message right here. So, display message.

  11. So, what we should be able to do is now set up some uh some validation. Say, hey, let's make sure this message is squeaky clean. Because before you would probably have a a validate validate rule that says um this is required a minimum of two maximum of well 255. We'll do that. And then we'll use livewire attributes of validate.

  12. Perfect. And then why don't we go ahead and make sure this is all working properly. So I'm just going to go composerdev and then we'll open up squeaky clean test. Pop that up. We'll register and looks good to go so far. So I can send a message. Hi there. Send. And we have hi there. We should probably clear that out as well. And maybe we'll just also set this to a class of flex.

  13. That's not really what I want, I don't think. Nope. But we'll go we'll say a class of flex. And we'll just say a gap of two. Let's see if that works. And perfect. Hi there. Perfect. Works pretty good. so far. We'll say uh this poll message and that should work for us right now. Hi there. Bam. All right. So, how can we make sure this is squeaky clean? Why don't we also set this to a p tag and we'll say a class of uh text.

  14. We'll just say class of MT uh 8. So far, hi there. Okay, we're ready to go. So, how would we validate this? Because right now we should have validation rules already set up and flux gives us some validation. So we should be able to say like okay if we hit here okay no validation um I believe what is the flux input now that I'm thinking about it. Uh flux errors is it just error field that I have to put in flux field. Yeah, I think I just need to put flux error.

  15. I think I think we're good to go there. Uh, I think I just need to actually put email or like the actual label and then we should be good to go there. Or not not even the label. I think we just need the type maybe. And we'll just say wire flux input and then we'll say type equals text. And let's see. We should have the actual input error now. Send. Okay, we get it. For some reason, it's not aha, we need to validate first. That's why this validates.

  16. Okay, but I'm not seeing that message. Maybe it's label equals your message. Curious if like when I I always forget when the actual validation errors pop up. So send one message. There we go. So it looks like you have to have that label showing in order to have that error message. But we always could also just add the flux error if we wanted to.

  17. Okay, back to the actual squeaky clean part. We just need to say that we want a new clean at the end of a specific validation. And because I'm doing this in live attributes, this should just work. We should say that this should be clean. Let's go ahead and take a look. So, we have uh this and I just want new clean. I'm curious if that should not should be outside of that. So, maybe we'll have to do this.

  18. And then let's go ahead and add this squeaky rules clean. Perfect. And so I'm curious if we have to do that validation in here. I don't know the actual syntax for LiveWire of how you how you add a new rule. I'm guessing this should work if I'm thinking through it correctly.

  19. Let's go ahead and do a test. I apologize in advance to my mom who is watching this. Um I'm just typing this to test this application. Okay. So we'll go ahead and say okay. um must be of type string. Okay, so we I didn't even have to test it just yet. Um this is not Let's go ahead and see. Um live wire attributes. Uh new rule. Is there a way to do that? Okay. Validate attributes don't support rule objects.

  20. They're restricted to certain syntax like plain strings and array. If you find yourself wanting to use runtime syntax like Laravel's rule objects, you should define a rules method in your component. So instead, we should do this. Perfect. So that's the preferred way. It looks like you should do that within LiveWire.

  21. Use the rules method. We probably could do the validate within this section here as well, but since the docs say so, why don't we do what the docs say? Okay. Um, let's go ahead and put a public function rules. So, we're going to return the message with um let's go ahead and say new clean and should be good to go there. And so, let me go ahead and pull this. Yeah. So, we should be able to say this is required.

  22. So, required uh min to uh max 255 and we should have new clean. Let's go ahead and see if that works. I'm going to remove this validation rule. That should be it. I don't know if this is the right syntax still. Let's go ahead and take a look.

  23. So, if we're back in our dashboard, we're going to do this. And no property bound for validation. Okay. Do we have message? Do you actually have to call a different rule when you're doing that? Let's see.

  24. And should be here. We just say we want this to be a new clean. Okay. Does it have to be like this? I'm guessing it it might have to be like that. So that way now validate required min does not exist. Interesting. It's probably because I'm not actually doing the proper syntax. So we should just be able to do something like this. We want the required string max of 255. We should even do like a a min of two and we should be good there.

  25. Let's go ahead and take a look now. Oh, so in our dashboard and refresh D. Perfect. And now again, Mom, Virture, please. I'm just typing it. I'm not actually saying it. Let's do this. It's pretty cool, right? Uh let's try some more. This is me just typing it. Uh let's say duck.

  26. That works great.

  27. Um, even the British are not safe from this. All right, I like it. Message fields required. We still get all that validation that we might want. Um, I wonder if you are able to kind of add additional, you know, logic to it. You probably can. Um, let's go ahead and take a look at the, uh, repo on GitHub just to see. So, yeah, it looks like you can use it as a clean rule. You can pass in specific languages as well.

  28. And then uh so any changes for words should be done in the profanify package. And I can't remember exactly what this one uses, but it looks like okay. So you can include specific words. So you can pass in an including argument.

  29. So, I don't know if you can actually do that within the package itself, but the things out of the box would probably do just fine for most people who are using something like this where you just need it to say, I don't want any of this in a particular like public chat message or maybe even in a username or profile or description of a profile or anything like that. But there probably is ways to expand upon this without having to make a PR to Profanify.

  30. But I would imagine there's some method within uh this new clean to say okay I want to actually you know pass it something. So yeah within the clean.php rule it looks like there is local a config file name. Uh but probably not yeah I'm not seeing anything to be able to pass in a new profanity.

  31. Um but there's probably ways of doing so or maybe um within like let's see configure ask confirm write in run slugify um this is probably just for something else uh something additional with it but there's probably a way that you could maybe make a PR to say hey this is a new word that should be added to this clean rule or maybe it's in a config or you just kind of extend profanify to do so within your clean settings overall Squeaky is really good.

  32. I mean, it just does what it needs to be able to do and it's going to be a great applica, a great package if you just need to drop something in really fast to say, "Hey, I don't want this in my application." And without having to do a bunch of reax or keep a list up to date, this does it for you. It keeps you to keep building and keep creating.

just you here