This is the full transcript of the Laravel News podcast episode #47 - “Vultures, relationsheets, and community contributions”
Jake Bennett: [00:00:30] Hello, everyone. Good evening from myself. Good afternoon from Mr. Dyrynda over in Aussie land. This is episode 47 of the Laravel News podcast, and I am recording in a houseful of sleeping women and children so I will be a little bit quieter than normal. I'm not going to be my normal loud, boisterous self if you can even imagine such a thing.
Michael Dyrynda: It's hard to imagine. I'll try and make up for it. Don't worry.
Jake Bennett: Okay. All right. [00:01:00] We've got ... I'm going to try and categorize this here for us. We've got a couple of releases for Laravel, 5.5.13, 5.5.14.
We've got a couple posts by one of our favorite human beings, Mr. Paul Redmond. We're going to talk about Hacktoberfest a little bit. We're going to talk about testing a little bit, some releases that have gone on. We've got a couple, and then that's it for basically Laravel News laravel news, and then we've got community links that are, we've got two [00:01:30] blogs, two eloquent things, two packages, and that's everything. We're going to try and get through all that today, so lot of good stuff here. Why don't we get started?
Michael Dyrynda: Let us.
Jake Bennett: Let us get started. All right. First up, let's talk about 5.5.13, so this was tagged on 9/24, so a couple weeks ago now. Is that right? A couple weeks ago or was that last week?
Michael Dyrynda: Yep. Two weeks now.
Jake Bennett: Two weeks now. Two weeks ago, so we just missed it.
Michael Dyrynda: It's addressing an ongoing issue related to a security fix [00:02:00] that was tagged in version 5.5.11.
Jake Bennett: Which we did talk about last time.
Michael Dyrynda: We did talk about that one, yeah. So this should be the last quick patch release related to the remember token fix, so definitely upgrade to 5.5.13 if you have not upgraded since going to 5.5.11 or 5.5.12.
Jake Bennett: I'm sorry. I'm going to let you ... I'm going to let it hang there for a second because I'm reading about this config option for the whoops blacklist. Have you looked at this? [inaudible 00:02:26] whoops built in blacklist ability. Trying to figure out why you'd even want to do this. Sometimes [00:02:30] I'm not the only one looking at my development work. I'll often show little previews of what I'm working on.
Michael Dyrynda: So this would be to blacklist certain keys within your environment or server or post.
Jake Bennett: Ah. Interesting.
Michael Dyrynda: So that in the event that you accidentally leave whoops on in your production environment, it's not going to dump things like your database password or your authenticator users password or your app keys [inaudible 00:02:57] or things like that. So that is a [00:03:00] very, very helpful addition. It's been merged into Laravel. I wonder if maybe it's a good idea to also push that into whoops itself.
Jake Bennett: Let's see.
Michael Dyrynda: Oh, no. It's a built in blacklist.
Jake Bennett: It says it was built in. It's built in blacklisting. Yeah. So now it's just kind of putting into a config in Laravel and whoops.php. This is interesting. I wonder if it also is taking out of the log. Probably not. Probably not.
Michael Dyrynda: Probably not.
Jake Bennett: Because this is just for whoops, so [00:03:30] I've had problems before as well, where it's not a problem, right? It's on your production server or whatever, where you might get a user's password if you were catching it or something and throwing something to the log, so I was wondering if it would kind of blacklist those values as well. Originally what I was thinking this was, was something like in your handler where you're ignoring certain types of exceptions, but that's not what this is. This is ignoring certain keys and making sure that they don't get dumped out to your whoops display when something occurs, when an error occurs. Yeah, that's a really good point, so makes [00:04:00] good sense.
Michael Dyrynda: Yeah. I mean, I would still caution against using whoops in your production environment at least with the full debug back trace, but certainly having a whoops config file and blacklisting any of those secret keys or passwords, your application key for example. I highly recommend that.
Jake Bennett: Very cool. It looks like there's also a collection method that got added in, and it is pad, so what this will do is it will take an existing array and then it will allow you to specify [00:04:30] a length that you would like it to be and what you would like to fill any missing values with. So, for instance, let's say you had an array that contained the values A, B, C. If you collected those values and then put pad and then for the first argument, the length of the array that you want it to be, 5, and then for the second argument, what you want to fill that with, let's say 0 in this case, your array would now become A, B, C, and then for the last two values 0, 0. [00:05:00] You can also specify a negative value, so instead of it being 5,0, 5 being the length of it, you can specify a negative 5 and instead of pushing those values onto the end, it will push them onto the beginning, so that's kind of interesting. I'm trying to think of a good example for when I would use it. I'm thinking maybe for stuff like select drop downs and things like that. Maybe.
Michael Dyrynda: Yeah. Nothing immediately pops into my head, but yes, certainly anywhere where you need to populate maybe have a consistent length [00:05:30] of items in the array.
Jake Bennett: On occasion what I'll do sometimes is, so not necessarily this, but what I may do is I may say if I know that I want to run something, like run a collection ten times, I'll just do a range, like collect range because I don't really care what the values are. I literally just want ten values. You know what I'm saying? Just run it ten times kind of thing?
Michael Dyrynda: Yeah.
Jake Bennett: Has nothing to do with what we're talking about right now though, so little tidbit for you. All right. That's 5.5.13. There's a couple other things on Laravel News you can check out, but that's, those [00:06:00] are kind of like the two that really mattered. In addition, we've got 5.5.14 which is a little bit more meaty. It's got a couple more things to it, so let's talk about that.
Michael Dyrynda: Sure.
Jake Bennett: One of the things that looks like, this is interesting. It allows passing a callback to with. I'm assuming this is going to be on eloquent.
Michael Dyrynda: The with helper, yeah.
Jake Bennett: Yeah, with is a global helper so you can say like, what I used to do with it is I would say like hey, new up a class [00:06:30] and then after that you would call a thing on it, so you'd say like with and then you'd say new user, whatever and then you would, after that you'd say username, arrow sign username equals jake or whatever. I don't care. Okay, so I think what it does now is instead of passing a value for that first argument, you can pass in a callback, so you can pass in a closure. Does that make sense?
Michael Dyrynda: So [00:07:00] previously, the with method took an object and then just returned that, so it was useful if you wanted to chain method calls onto that.
Jake Bennett: Sure.
Michael Dyrynda: [crosstalk 00:07:08] with new user and then you could call methods directly on it, so it's a bit, I guess nicer than just paren new user paren and then chaining it that way. With the change that's been introduced in this release you can now pass it any value and optionally pass it a second parameter which is a callable function or whatever [00:07:30] else and it will pass that value through the callback before then returning the value.
Jake Bennett: Ah, interesting. Okay. Sure. That makes sense. So he said, he compared it to like tap in his, he said similar to tap but returns the value from the callback.
Michael Dyrynda: Yeah, whereas tap let's you modify the object, but it doesn't return ...
Jake Bennett: Right. Yep. Exactly. So a good, yeah, so for like tap, if you said, if you had called a user already and then you were going [00:08:00] to call an update function on it, the update function just returns a Boolean and a Boolean doesn't particularly useful, so you just want to, you would say tap user and then you would call your closure which would then do the update for your user. So it returns back to you the original, right?
Michael Dyrynda: Yeah.
Jake Bennett: But this one, with, would return it after it's been passed through the call back.
Michael Dyrynda: Yeah. So one thing that got me, that stumped me initially with the tap method was that you can't return a tap because it doesn't intuitively return whatever the modified value is inside of [00:08:30] the callback on the tap method, so now with with, you can do that. So if you wanted to manipulate something just before you return it from a controller method for example, you could do it using the with method instead of the tap method.
Jake Bennett: Gotcha. That makes sense. That's cool. One little tiny one here. There is a make exception command that's been added so you can do PHP art as in make exception and then specify your exception. You may find yourself doing this more now that you have a render method that is available on any custom exceptions that you have, and you can handle all your rendering in there. [00:09:00] I mean, honestly man, there's so much stuff in here that it's like, whatever. Here's the deal.
Michael Dyrynda: It's a pretty meaty dot release.
Jake Bennett: It is. I love Laravel. It's amazing. We talk about this stuff every two weeks and we look through these change logs in depth, and we still don't know what half of this stuff is. I mean, how much time would you have to invest to actually know the entire scope of everything that's going on and be able to utilize all of it. It's just insane. [00:09:30] The popularity of Laravel has just gotten to a certain point where it's literally like I don't know how you could maintain, like if Taylor and Mohammed, like they're going to have to hire a third person, seriously, right? Like how many pull requests are there a day I wonder. I'd be interested to know.
Michael Dyrynda: Yeah. Speaking of pull requests, one thing that I saw very recently and I don't know that it has been tagged in yet, but Caleb Porzio and Kieth Demiani both from Tightenco were [00:10:00] talking probably about a week ago about the ability to make assertions in your dusk tests based on components from Caleb and also the ability to then reach into those components and make assertions about the state of the data in the component. So I'm pretty sure Taylor threw that out as a little challenge to those two guys and it was only a few hours later that Kieth actually brought that functionality [00:10:30] in, and I believe it's been merged in yet. I don't know for sure that it's been tagged at the time of this recording, but essentially what this is now allowing you to do is to make an assertion on the state of the data within a view component in your Laravel dusk tests.
So if you are trying to make assertions about, you click on a button and it's supposed to change some value, previously you would have to look at the output to see what had happened, but there was no way of looking at the data property in your view component. [00:11:00] Now you can make that assertion directly in your dusk test, and Taylor has written a blog post about it as well, so we will link that up in the show notes, but I thought that was really handy, especially as someone who had just written his first lot of dusk tests in the last few weeks.
Jake Bennett: That's awesome. Yeah. I did see those.
Michael Dyrynda: It certainly made that much, much, much easier because I was, as I said previously what you would do is you would have to fire like a click event into your page, into your [00:11:30] loaded page and then you would simply make sure that some other value had been created, so that then created this situation where I was adding id attributes to elements or I was adding data attributes simply so that I could target my tests and which generally you don't want to do. You don't want to change your output to make the tests work, so this way you can certainly target the components that you've already got and then look at the data inside them, so [00:12:00] Keith Damiani made that change. That has been tagged in dusk version 2.0.6.
Jake Bennett: Yeah, it's like snapshot testing, right? So it take snapshots of your component state at a certain point in time and then you can make assertions based on that, so that's pretty neat. There's also this idea of component objects, that's think what Caleb was pushing out there, right? So like you can have pages but you can also have component objects which would be a really clear way [00:12:30] to be able to test those components kind of like in their little isolated units without having to reach inside, reach inside, reach inside or whatever. You can just, if you go look at the pull requests in his proposal, it's really, looks really, really good.
Jake Bennett: Yeah, that's what I'm looking at right now.
Michael Dyrynda: At which point it might have got all too much, overwhelming and you would have just gone well, this is close enough or now, as Laravel tends to do, as the community tends to do, all at once with their crazy hive mind mentality is we need this thing and suddenly that thing appears, so kudos to Caleb and Kieth and even Taylor just for putting the challenge out there to those [00:13:30] two guys to get it done.
Jake Bennett: Yeah. It's pretty awesome, so Jest is used for React, right? So Jest has got that basically, it's easy set up, instant feedback, snapshot testing, zero configuration testing platform, but it's another thing, right? It's another thing to add to your testing list, so ...
Michael Dyrynda: Yeah. Whereas Laravel has always really pushed, not only developers to write tests, it encourages to make testing easy.
Jake Bennett: Right.
Michael Dyrynda: And whenever we hit a pain point as a community, we try and solve that thing to again, make testing easier, [00:14:00] so you don't have to sort of step out and learn other, I mean, I encourage you to go out and learn those other things, but if you're one of those developers that has got their head down and is trying to get things done and trying to make them robust by writing these tests, then Laravel certainly makes it a lot easier than trying to do everything from the ground up.
Jake Bennett: For sure. So thank you, Tighten for volunteering these dudes' time. Thank you Caleb. Thank you Kieth. Thank you Taylor. Okay. We've got debate here. VULTR. VULTR.
Michael Dyrynda: [00:14:30] VULTR.
Jake Bennett: Is it VULTR?
Michael Dyrynda: VULTR.
Jake Bennett: Or is it a clever name vulture?
Michael Dyrynda: No.
Jake Bennett: This is a debate between Michael and myself. I think it's vulture. Michael thinks is vultr, and I'm not sure which one it is. All I know is that they're logo is a little bird. It looks like the old Twitter icon, little Twitter, actually a little blue bird.
Michael Dyrynda: It's a cute little bird. It is not intimidating. It's not a vulture. It's not going to hurt you.
Jake Bennett: Right. It's just like ...
Michael Dyrynda: It's Vultr.
Jake Bennett: VULTRE. Is that how you spell vulture? How do [00:15:00] you spell vulture?
Michael Dyrynda: No. Vulture. V-U-L-T-U-R-E.
Jake Bennett: Vulture. Sorry.
Michael Dyrynda: V-U-L-T-C-H-E-R. Vulture.
Jake Bennett: L-T-U-R. No this is a common thing, right? Where like you remove ...
Michael Dyrynda: You remove a vowel.
Jake Bennett: Oh, my gosh. I'm like, I don't know what's wrong with me. I literally cannot think right now. Where you remove vowels, right? It's vulture. It's definitely vulture. You're wrong. I'm sorry. We're going to have to take a survey. We're going to have to put a survey [00:15:30] out there. I think it's vulture. Anyway ...
Michael Dyrynda: I think we do. Put a survey out. How do you pronounce it, and then we'll get Vultr to vote and we'll see what happens.
Jake Bennett: The news is that it is now supported on Forge, so you can provision boxes straight from Forge onto to Vultr.
Michael Dyrynda: Yes.
Jake Bennett: There you go.
Michael Dyrynda: Yes.
Jake Bennett: Okay.
Michael Dyrynda: I've been using Vultr for the better part of two years, and every time I've asked Taylor, he's said it's difficult because they have different server sizes available at different times in different [00:16:00] regions in different data centers, so it's always been tricky to be able to then present those options in the Forge UI, but it looks as though they have figured out how to do that, whether that means that Vultr has added that to their API or Mohammed and Taylor have come up with some other clever way of doing it. I don't care. I can now spin up those servers right from the Forge UI without having to go and manually spin one up in the Vultr UI and then come back to Forge and then copy and paste the URL [00:16:30] to do a manual install and all that kind of stuff. So, thank you. I do encourage anyone who wants to look at a different option, the main reason, and for me the main reason that I use Vultr is because they have a point of presence in Sydney.
Jake Bennett: That's what I thought.
Michael Dyrynda: In Australia.
Jake Bennett: Right. It's in ...
Michael Dyrynda: Where Digital Ocean, they've been talking about it for as long as I've been with Vultr, and as soon as I found out, look, it was five dollars a month at the time. They now hae servers starting from as little as two dollars fifty a month which I think gives you something like ...
Jake Bennett: [00:17:00] That's something we take for granted as Americans, right? Like, bell lag time is real, right? So, you can't use AWS stuff. You have to use Google because AWS doesn't have anything in Australia, right? And Google does or they have something on the west coast?
Michael Dyrynda: We had AWS. It was just more expensive than what Google was.
Jake Bennett: Gotcha. Gotcha.
Michael Dyrynda: Yeah, but two dollars fifty with Vultr will get you 20 gig of solid state storage. It gets you 512 mega memory and it gives you 500 gig of bandwidth, so super easy to use it [00:17:30] get up and running.
Jake Bennett: Wait, wait, wait, wait. You said it's two fifty?
Michael Dyrynda: Two dollars and fifty cents.
Jake Bennett: Then Vultr it is. All right. I know what I'm doing. Tonight. I'm spinning up a box, two fifty. Seriously, two fifty. That's awesome.
Michael Dyrynda: Spin it.
Jake Bennett: Yeah. Sweet. Thank you Taylor. Thank you Vultr. Okay. Hacktoberfest 2017. Does everybody know what Hacktoberfest is? Let's talk about it. What is Hacktoberfest?
Michael Dyrynda: Please tell us. Tell us.
Jake Bennett: Okay, I will tell you. I'll pull a Michael. Thank you for putting me on the spot, Michael. All right. Here we go. No, [00:18:00] I'm just kidding. Hacktoberfest is a thing sponsored by Digital Ocean and GitHub and you sign up and the goal is to get at least four pull requests to public repos on GitHub. If you are signed up and you do that, you get a special edition Hacktoberfest 2017 T-shirt sent to your doorstep. If you don't get the pull requests in, you still get stickers if you sign up. Everybody gets stickers. Only the people who get four public [00:18:30] pull requests pulled in get the T-shirts. So, I'm going for it. I didn't get a chance to do it last year, so I'm going for it this year. I've got a couple out there so far. I think I've got one. I've got another one I'm working on and then it should be no problem to find two more. There's a million projects out there.
Michael Dyrynda: And look, I don't think you even need to have them merged. I think it's just a matter of submitting the pull requests.
Jake Bennett: Oh, really?
Michael Dyrynda: I think it's ... Yeah, I'm pretty sure it's just encouraging you to open, obviously don't open rubbish.
Jake Bennett: Right, right.
Michael Dyrynda: Like, don't make open [00:19:00] source maintainers lives difficult. There have been heaps and heaps and heaps of pull requests on little things within the Laravel documentation, typos and if you see a method that's not documented then submit a pull request. The worst case scenario you get a free t-shirt at the end of it, so well best case scenario. It depends on how you look at it.
Jake Bennett: Right, and if you're looking for something and you're like oh, I don't know anything. Yeah, do some documentation. Go look through Laravel documentation, see if there's anything that you can find, like a feature that's not documented or something like that and go [00:19:30] do the documentation. You don't have to be super technically ...
Michael Dyrynda: Fix a typo.
Jake Bennett: Yeah, fix a typo for goodness sakes.
Michael Dyrynda: But be careful. Don't submit multiple pull requests to the same file at the same time because all you do is you're going to end up with merge conflicts which again, open source maintainers don't want to have to deal with necessarily, so feel free to contribute but be helpful.
Jake Bennett: There was like a threshold, too. GitHub has got an intelligent algorithm that looks for fraudulent pull requests if you're just trying to hit your four, so yeah. Make [00:20:00] sure it's helpful. Make sure it's useful. Okay. Yeah. We're going to go straight to the community links. We love our community, don't we? Don't we love our community?
Michael Dyrynda: Community is the best part of Laravel.
Jake Bennett: Community is the best. It is. So, we are going to talk about what all of you have sent in, and let's start with the key is the key. Did you read this?
Michael Dyrynda: I skimmed it, but I didn't read it in great detail, so I'm going to rely on you to tell me what it's all about.
Jake Bennett: Okay. So, [00:20:30] this has to do with how stuff is sorted when using the sort by method on a collection, okay? So, if you have multiple things that you want to sort by, so let's say last name and then first name. If you want to do that, so let's say you have all of your users and you grab those back and then you want to do a sort by afterwards, not an [00:21:00] order by, okay? We're not talking about order by, we're talking about sort by, so you have all your users in a collection already and you say sort by, what you have to do is, I don't believe you can pass in multiples. What you have to do is it's fluent, so you have to say sort by and then give a key and then sort by and then give a key. So if wanted to sort by last name, first name you would think that you would say users sort by last name, sort by first name, thinking that it would sort by the last name first, and then sort by the first name next, right?
It does not. [00:21:30] In fact, what it has to do is you have to do it in reverse. So if you want to sort something, you have to make sure you put the keys in reverse order. So if you wanted to sort by last name, first name you'd have to say user sort by first name, then sort by last name. If you want to know why it's doing that, there is, that's exactly what this post is detailing. I'm not going to go through the entire thing for you. It's not worth it, but Keith Diamani actually did, I think he did some research on this and people were [00:22:00] a little bit worried like ooh, that doesn't really seem intuitive and it's true, but that's just kind of how it works, and the concern was that it was going to be maybe broken in future versions if they fixed it or whatever and people were utilizing it, kind of like utilizing that bug in the system to make it work, that if they fixed it, it would break everybody's stuff. So I think what they decided is that it's going to continue to be like this, and that's just how it is. It's just how it is.
So helpful little tidbit there if you ever find yourself in that situation, you want to sort by multiple [00:22:30] keys, make sure you put those keys in reverse order. I actually have a blog post out there, too, about this. Yeah. It looks like if you're using raw SQL, like if you do order by, they go in reverse order as well. So if you're writing it raw, if you're writing in raw SQL you have to write the order bys in reverse order as well. If you're setting them equal to like specific keys, and it's kind of an edge case. Okay.
Michael Dyrynda: Okay.
Jake Bennett: So, anyway, yeah. The key is the key. Important to know. Make sure that you, when you're sorting by multiple keys, [00:23:00] I will say this for the fifth time probably, put them in reverse order. There we go. Okay. The next one, you know what? I'm not going to let you take the next one because this was like life changing for me this week. So I'm taking it. It's mine.
Michael Dyrynda: Go on.
Jake Bennett: Okay.
Michael Dyrynda: Cool.
Jake Bennett: Do you know what I'm talking about? What am I going to talk about?
Michael Dyrynda: I know what you're talking about.
Jake Bennett: Hit me. What am I talking about? Introduce it for me.
Michael Dyrynda: Do our listeners know what you're talking about?
Jake Bennett: Yeah, introduce it for me. Lead into it for me. Here we go.
Michael Dyrynda: There has been lots of rumbling, lots of noise, lots of discussion lately, perpetual requests and [00:23:30] tweets and things like that about Docker and PHP and even Laravel. So Jake, why has docker been so powerful for you this last week?
Jake Bennett: Well, let me tell you. So I had a legacy code base and I'm running Valet. Valet for everything, right? Valet for the win. Running PHP 7.1, but the problem was that this legacy site had been developed and is currently running on PHP 5.6 on Apache, so when I would try and run this site on my local machine and run it on Valet, this thing is just chucking [00:24:00] errors and it's not, it does not look pretty and I had messed with it for a long time. It's a legacy code base, so I gave up, was like screw it, not going to do it, and then our man Paul Redman posted a great blog post called A Simple Keyword. A Simple Approach to Using Docker and PHP. I know number one, Paul's a great teacher and number two, if he says it's simple, it's actually going to be simple, so I was like all right. I'm going to try this out.
So, I followed his blog post and I had a Docker machine [00:24:30] set up on my box running PHP 5.6 with Apache with MySQL in about 15 minutes, and I was like you've got to be kidding me. That was so easy, and it worked perfectly. It did exactly what I needed it to do, so that was a couple of nights ago, and I did it again today for a really legacy site, but it didn't even matter. It doesn't matter how old legacy it is because it's just, I mean, whatever, so you know, I know you can do bigger machines and stuff like that, whatever, but Docker is the new hotness [00:25:00] and who doesn't want to know a little bit about Docker because I knew absolutely nothing, and this blog post made it super easy to get started. So, if you need to containerize, if that's even the right word, some legacy app that you want to run on your machine, I would highly suggest checking this blog post out or if you've just been curious about Docker and you're like what's this whole Docker thing about? How do I get started this? Check that out. Check that blog post out. It's really awesome.
Michael Dyrynda: Can I let you in on a little secret? I also have a legacy application, but my application [00:25:30] is very legacy. It is running on Apache 2.2 and PHP 5.4.
Jake Bennett: No. 5.4?
Michael Dyrynda: Yes. It is ...
Jake Bennett: You are past [inaudible 00:25:41] life, my friend.
Michael Dyrynda: It is horrible.
Jake Bennett: I don't even know if they have Docker images for 5.4. Let me see. Docker Hub? Is that what it is?
Michael Dyrynda: Gosh, I hope so.
Jake Bennett: Hub.docker. Okay, here it is. Hold on. I'm going to look it up.
Michael Dyrynda: But when I got to this new job and I saw that it was PHP 5.4, I said I'm pretty sure I'm going to have to do this in a Docker [00:26:00] container because there is no way that I'm polluting my poor, poor little MacBook with PHP 5.4.
Jake Bennett: I am sorry to tell you that Docker Hub does not have an image for 5.4. I'm sure there's probably some other image out there, but it's not ...
Michael Dyrynda: I'm sure there's some dirty, horrible hack that will let me get it running, but ...
Jake Bennett: I'm sure there probably is.
Michael Dyrynda: And look, I don't blame them. Why would there be a Docker image for something that is dangerously, it's vulnerable, it's ... Look, you don't have to teach, you are preaching [00:26:30] to the choir, my friend, but Docker may be my shining light here.
Jake Bennett: I think it's probably going to be your shining light, if you can get it to run on Docker, but ...
Michael Dyrynda: It will certainly make it easier for me to figure out how to upgrade this thing from 5.4.
Jake Bennett: No doubt. No doubt. So, huge shout out to Paul. Huge shout out for that blog post. Also, I'm just going to give a shout out to Mr. TJ Miller. Six live, today he helped me with my Docker stuff for a half hour, and I'm expecting to get, still get an invoice for his consulting fee, but I don't think so. He's just ...
Michael Dyrynda: Yeah. He's going to have to start charging people because ...
Jake Bennett: I think he should.
Michael Dyrynda: Yeah, I've had [00:27:00] so many people have tweeted and sent him kudos for helping them out with getting Docker up and running and he's, I know he's really busy and he's still finding time to help people out get this stuff up and running.
Jake Bennett: Thanks, TJ.
Michael Dyrynda: Thanks, TJ.
Jake Bennett: Also Paul's coming out with a book, so we'll talk about that. We're going to have him on. We'll talk about it at that time. He's coming out with a Docker book, so that'll be great.
Michael Dyrynda: We will.
Jake Bennett: Okay, let's talk about Eloquent. I'm going to let you take some of this stuff. So let's talk about Eloquent relationship cheat sheet. Talk to us about this.
Michael Dyrynda: [00:27:30] Okay. So, there was a link submitted via our community link section on the Laravel News website by, and I apologize in advance for my pronunciation here, Mamoud Zult.
Jake Bennett: I think that was pretty good. I think you got it.
Michael Dyrynda: I mean, that's how it looks, so I'm hoping it's close, but he has submitted a link on Eloquent relation sheets.
Jake Bennett: Relation sheets?
Michael Dyrynda: Eloquent relationship cheat sheet. So this is a cheat sheet [00:28:00] for Laravel's Eloquent RM version 5.5, so it is up to date and it is a great run through of the various relationship types supported by Eloquent out of the box. So it goes through one to one's, one to many's, polymorphic one to many's, many to many's and polymorphic many to many relationships, and it talks about, it gives you a little demo about business rules, so for example, for a one to one relationship, there are two models, an owner and a car, and two tables, [00:28:30] owners and cars, and the business rules are that the owner can own one car and that the car can be owned by one owner. So they key there is on, I guess that the naming, the owner can own one car and the car can be owned by one owner. So it has a little diagram there on what it looks like for an owner to own a car and it shows the inverse of that relationship, so you've got a has one relationship on one side for the owner and a belongs to on the other side for [00:29:00] the car.
Jake Bennett: Which are actually the methods that you would use to define the relationships in your Eloquent model which is where this is really helpful.
Michael Dyrynda: That is correct.
Jake Bennett: Because those are the things that you forget a lot of times, right? You're like I know this is a one to one. What is the relationship I need to use and how do I define the inverse relationship, so it's like okay, return has one, return belongs to, yeah.
Michael Dyrynda: Yep. Yep, and it reads nicely in English, so if you look at your Eloquent model, you'd have an owner model and your owner model would have a car relationship, and the easy way to remember it is that an owner has one [00:29:30] car.
Jake Bennett: And it does read nice because you say this has one, right? You say return this has one and then you specify the relationship as this has one car, and then you say car, this belongs to owner, right? Yeah. It reads super well.
Michael Dyrynda: So the car belongs to an owner. So it reads very well. I'm sure there was a lot of pain that came into coming up with the right naming and I'd like to credit Taylor but I think even before that with Rails and Active Record, the original implementation, I'm pretty sure that's where those names come from, but it is [00:30:00] super intuitive. It explains what's happening. It's easy to read, and so that's one relationship type, but it also talks about what your models look like, what your migrations would look like for each of the tables, how you would implement the foreign keys and then it also talks about the methods that you would call to store and retrieve those related models, and that's the thing that always trips me up is when to call which method on what model, so I think I'm going to keep this page bookmarked.
Jake Bennett: Yeah, absolutely. [00:30:30] And there's some other stuff, too, so not everybody is a learner where they learn by reading or whatever. There's a lot of people who are visual learners and just need like a diagram, like if you could just show them a diagram, and so these diagrams are really very intuitive. So if you've not worked with relationships before, just like if you're new to databases even. If you're just trying to figure out what is this one to one, one to many, many to many, all this stuff, what is this? How does this work? These diagrams will help you out a lot in kind of figuring out what that it. [00:31:00] The polymorphic stuff is a little bit more, I don't know if you'd even call it advanced. I don't know if you'd call it advanced but yeah.
Michael Dyrynda: It's a bit more involved.
Jake Bennett: Yeah, you might end up finding yourself asking where would I use this? How would I use this? Adam Webb has got a great post out there called Pushing Polymorphism to the Database, and he talks about coupons and different types of coupons. So instead of defining, trying to have all the properties for all the different types of coupons in one database record, he [00:31:30] has a coupon but then it references these other, you can cast it basically. You can transform it into this certain, these different types of coupons, whether it's a percent off coupon or a fixed amount coupon or whatever. So if you're looking for how would I implement these polymorphic relationships, so what's a good example? That would be a great post to go check out. We will link that up in the show notes.
Michael Dyrynda: Yeah. The other one that I have come across more recently and personally is just storing notes against customer records, [00:32:00] so we have a notes table so you can store notes against a customer or you can store notes against a specific service that belongs to that customer, and that's where you can leverage polymorphic relationships. So you would only ever have a notes table and then you can just relate the type of note, whether it's a service note or a customer note in that one place and they can all maintain their own state and things like that. So, yeah. Thank you very much to Mamoud for this post. Thank you to Adam for his post, both [00:32:30] of which we will link to in the show notes.
Jake Bennett: Excellent. We also have Jesse Schutt, I think is how we say his name. I always said like shoe-it. I don't think that's correct, so it's Schutt. Must be Schutt.
Michael Dyrynda: Sounds like and open and shut case.
Jake Bennett: There we go. This is one of those things, again, this last one we talked about with the cheat sheet as well as this. These are things that if you've been using Laravel for any amount of time, you're probably aware of these things and you probably have used them before, [00:33:00] but it's good for a refresher or for people who are newer to the community and haven't checked out any of this stuff. So these combo methods, what he's talking about is methods in Eloquent that you might use like first or new, or first or create, or find or new, or update or create, these combo methods where the method includes two things, and what this allows you to do is it allows you to kind of shortcut that check that you'd have to do to say hey, do I have a user here? If I don't have a user, go ahead and create one instead of having to do that in [00:33:30] two lines or using a conditional, you just do it in one go. So user, find or create and then you can specify here's the array of data I'm looking for. If that does not exist, go ahead and create a new user with these values, right?
So, it's definitely worth a look at, and you might find some stuff that you did not know about. It's super helpful, man, these combo methods. They can save you a lot of code and really clean up your code base.
Michael Dyrynda: Yeah, and even if you're maybe familiar with those methods, [00:34:00] you may not be familiar with the fact that you can actually pass a second parameter to them, so I won't spoil any of that on air, but we will certainly link up and encourage you to read the blog post in the show notes.
Jake Bennett: Yeah, please do. Yeah, like I said, I'm even looking through this here, and there are some of them that I've not used before or didn't know really a thing, so yeah. Check it out. Okay, we also have a couple packages. We are going to move into the packages section. I have two that I wanted to talk about. The first one [00:34:30] you seemed to know more about than I did as far as how they're doing it, so why don't you take that one? Validating credit cards. Of course, nobody should be validating credit cards anymore anyway because you should all be using ...
Michael Dyrynda: Something that does it for you. Anything. Literally anything that does it for you, please use it.
Jake Bennett: I wonder if Adam is doing this one kite tail. I wonder if he has to validate credit cards? Probably.
Michael Dyrynda: It's a simple check, like it can be forged. All it does is verifies that it is a valid card number.
Jake Bennett: Okay.
Michael Dyrynda: So there is a formula.
Jake Bennett: Sure. I'm sure.
Michael Dyrynda: [00:35:00] There is a formula that is used to calculate credit card numbers, and it's basically a, it just uses a checksum to make sure that the number is valid, but whether or not it is an actual credit card is a different issue entirely, and that then comes down to your payment provider. It comes down to the card issuer to then say yes, this is a valid [inaudible 00:35:21].
Jake Bennett: What is the formula used? You had a name for it.
Michael Dyrynda: It's called the Luhn Algorithm.
Jake Bennett: L-U-H-N?
Michael Dyrynda: L-U-H-N. Yeah. Luhn Algorithm or [00:35:30] Luhn formula. It's basically a mod ten algorithm which I won't explain.
Jake Bennett: Yeah, don't.
Michael Dyrynda: Because I don't know ...
Jake Bennett: It doesn't matter.
Michael Dyrynda: But it's basically a simple checksum that is used to validate credit card numbers, IMEI numbers that are used to identify mobile phones. There's Canadian social security numbers and things like that, so it's basically just a checksum of the number to make sure that left to right it is a valid number.
Jake Bennett: Yeah, so what this package does is it basically provides you a Laravel validator, right? In [00:36:00] Laravel validation you have numeral, digit whatever, but you don't have a validation method for credit cards, so this essentially provides that. So this is a Laravel credit card validation method, and you can just pull it in as a package which is pretty handy. I had to learn that stuff in college. I was a math ed major, so I had to do number theory, was one of my classes and we had to learn about checksums and mods and pretty cool stuff actually, but I don't remember any of that.
Michael Dyrynda: I did actually have to implement this. I didn't have to, but this was a few [00:36:30] years back just before I finished up at a job so I was spending some time like really over engineering some of the code that I was writing before I left.
Jake Bennett: Nice.
Michael Dyrynda: Testing was not common there. Object oriented programming was not common there, and so I was just sharpening my tool set, making everything object oriented and writing tests for everything and going to extremes on validations, so ...
Jake Bennett: Because why not?
Michael Dyrynda: Yeah. Yeah. It's interesting stuff. You want to keep your brain sharp [00:37:00] and learn new things and learning how to implement a formula like that is interesting to some people [inaudible 00:37:05].
Jake Bennett: Yeah. All right.
Michael Dyrynda: But yeah. Definitely we will link that up in the show notes. What was this other one that you had on here? Laravel Talk. Tell us about that, Jake.
Jake Bennett: Yeah, so this looked interesting to me because I've had to do, I mean, it seems like a waste of time, right, to be like oh, you're going to implement this chat thing or this talk thing. Why don't you just use email or why don't you just use some sort of messenger like Slack and things like that, and that's fine. That is a valid point. [00:37:30] However, what if you want to validate or track what was sent and if the person who was supposed to receive it actually read it? So that's why this kind of peaked my interest. I had for like, it was like a coaching sort of thing where a manager goes in and they can see what, you know, the metrics that they've defined for their team to hit, their key performance indicators, and they can kind of send a message coaching them. Hey, we need to work on this number for today, try and get it up to five by the [00:38:00] end of the day, whatever, and when they send that message, we needed to make sure that the person who is supposed to receive has read that message within a couple minutes, whatever.
And if they haven't then we need to go talk to them because these messages are important like when they're sent. So, I had to implement that, which seems sort of silly. It was like kind of like inventing email again or reinventing email again, right? So this Laravel Talk package essentially is a user conversation inbox system with real time messaging. So you can think of it like a little [00:38:30] chat box that you could put at the bottom of one of your pages or whatever, but it's just, I mean, it gets you started and whatever in like about five minutes, so you can then modify it, right? It's built on Laravel 5.5 and it uses, I'm sure a lot of it, the messaging stuff that's, not messaging stuff, what am I looking for? I'm sure it uses like echo and things like that to handle the real time aspect of it. So yeah. I thought it was worth a check out, and if that's something that you've had to implement [00:39:00] in the recent past or something you're looking to do in the future, it might be a good starting point for you.
Michael Dyrynda: Yeah. Definitely.
Jake Bennett: All right. We had an extra here on the bottom, and you wanted to talk about this maybe.
Michael Dyrynda: Why not? All right. So this one last one is from the team over at Laravel Daily, written by Povilas Korop. I hope I got close there. He's very active on the Laravel Daily website. He's always blogging. He's got some videos that he puts out on YouTube from time to time. This post [00:39:30] is about expiring passwords and forcing users to change their password every X days. In some environments in some sectors, it's common. I don't know, maybe Jake, you, do you have those kind of receptions?
Jake Bennett: Yeah, we do.
Michael Dyrynda: Maybe not in your web apps, but ...
Jake Bennett: No, I don't have to handle it in my application because it's all handled through Active Directory.
Michael Dyrynda: Because you Active Directory. Yeah. Sure. So I mean it's something. Anyone that's ever been in a Windows SOE environment, it's usually part of that, where you will have to reset [00:40:00] your password every 30 days or 60 days or whatever, but there's not been a really good way of doing that within Laravel, so this blog post runs through tracking when the password was last changed, creating a page to then force users to reset their password periodically, check when they log in. I don't know that it handles necessarily ... It does. So there's also a middleware to check your expired passwords, so it you are logged in with a password that hasn't [00:40:30] been reset for 30 days it will actually boot you back to an expired password page and force you to reset it, so if that's something that, yeah, if that's something that you need to deal with within your web applications, certainly check it out. The link will be in the show notes.
Jake Bennett: Yeah. Thank you Povilas. I'm going to get that wrong. That's terrible.
Michael Dyrynda: Povilas, I reckon.
Jake Bennett: Povilas Korop.
Michael Dyrynda: Povilas Korop.
Jake Bennett: Yeah, he has been kind of doing crazy stuff like that. He's got a YouTube channel and everything I think.
Michael Dyrynda: Yeah.
Jake Bennett: I've not watched much of his stuff, but I know he's doing a lot of stuff.
Michael Dyrynda: Yeah, hopefully we'll hear [00:41:00] from him on our sister podcast over on the Laravel podcast with Matt [inaudible 00:41:05] at some point in the future.
Jake Bennett: Yeah, that would be really cool. All right. Hey, I think that wraps it up. It's 12:45 here. So I'm going to go to bed. I just finished painting a little while ago. I got painting, we're redoing a bathroom. Fun times.
Michael Dyrynda: Well, I was going to ask you about that. You had paint all over your hands.
Jake Bennett: Well, let me see. Do I have paint? How did you see my hands?
Michael Dyrynda: Well, you were holding your hands up.
Jake Bennett: Okay.
Michael Dyrynda: You were doing a Mr. Burns impression before.
Jake Bennett: Doing my gang signs. [00:41:30] Yes, I was painting and I've got paint all over my hands. I wear these gloves usually now, so I don't get paint all over my hands because then people always ask and harass you. Are you painting? Whatever. It's annoying.
Michael Dyrynda: Are you still painting?
Jake Bennett: Exactly. So, I usually wear gloves now but ...
Michael Dyrynda: I'll give you free board when you come and visit and you can paint my house.
Jake Bennett: A board? What's a board?
Michael Dyrynda: Board. You don't know what board is?
Jake Bennett: No. What are you talking about? You'll give me a ...
Michael Dyrynda: Like room and board.
Jake Bennett: Oh, okay, okay, okay. I thought you said you'd give me a free board, like I'm going to paint with a board.
Michael Dyrynda: Yeah, I'll give you free board, [00:42:00] room and board.
Jake Bennett: I got you.
Michael Dyrynda: And you can paint my house in real time.
Jake Bennett: I got you. So yeah. I had to clean up though, and I was in a rush to get done so I could record this podcast, and so I got paint on my hands.
Michael Dyrynda: Well, we appreciate it.
Jake Bennett: Thank you, everyone so much for listening to another episode of the Laravel News podcast, episode 47. You can find show notes for this episode at laravel-news.com/podcast/47. If you have any questions or comments feel free to hit us up on our personal Twitter accounts [00:42:30] or at Laravel News. Write us up. Write us up in your pod catcher of choice. Everybody else has been saying this recently, like five stars only. I think that's sort of like, that's a cop out, right? It's like we don't want honest feedback, people.
Michael Dyrynda: I guess.
Jake Bennett: We don't really want your honest feedback. We only want five stars.
Michael Dyrynda: If you don't think the show is worth five stars, please, please, please reach out to us on Twitter or via email or you can find us on the internet. Please, please, please tell us what it is that you don't like about the [00:43:00] show that week. We can make it better.
Jake Bennett: Yeah, what do you guys want? What do you guys and girls out there want? What do you want us to change? We are very responsive to this stuff. So hit us up. If it's negative, if you want us to change something, just tell us. If you want to get a shout out on the show, if you want to do that, just message us. We'll probably do it. So talk to us. Let us know what you want. We're happy to help out in that way. And if you've made it this far in the podcast and haven't shut if off yet, I congratulate you. Well done. All right. [00:43:30] I think we're it. I think that's it. We're all done.
Michael Dyrynda: Yeah, I think so.
Jake Bennett: Okay. If anybody hears little chirping in the recording, that's Michael. That's not me. He's got little birds outside in Australia.
Michael Dyrynda: It is spring. It is spring.
Jake Bennett: Spring there, and it's fall turning to winter here. It's so weird. I've been reading this book called The Spin Saga, and it doesn't really have to do with seasons but it's kind of interesting. Check it out if you're looking for a good sci-fi.
Michael Dyrynda: All right.
Jake Bennett: Okay, I think it's too late. I'm like punch [00:44:00] drunk right now. I need to go to sleep.
Michael Dyrynda: Yeah.
Jake Bennett: I am. And I'm going to guard my book now. Wait for a couple minutes.
Michael Dyrynda: Which is normally what I'm like when we record these shows.
Jake Bennett: Yes, because you've just woken up.
Michael Dyrynda: So I appreciate that we're wanting to do this when it's later in the day for you, so I don't have to get up quite so early.
Jake Bennett: I think we're going to have to do this. This is going to have to be our new time. Late on Friday nights. Okay. Sounds good. I'll let you go, man.
Michael Dyrynda: All right. We will speak to you all in two weeks.
Jake Bennett: Sounds good. Thanks everybody. Bye.
[00:44:30] Boom. We are recording. Okay. Well, so far we've had phantom bird noises. We have had you telling the wind to quiet down.
Michael Dyrynda: Yeah.
Jake Bennett: We have discussed whether it is vulture or [00:45:00] vultr.
Michael Dyrynda: Yeah.
Jake Bennett: Which I believe it is vulture. We have discussed the pronunciation of Jesse Schutt's last name and made some funny jokes about saying it like curse word. That's not a curse word.
Michael Dyrynda: I'm just more interested that you called him Jeshi instead of Jesse.
Jake Bennett: Jeshi?
Michael Dyrynda: We don't discuss how to pronounce his first name. Maybe we should have done that before we started recording.
Jake Bennett: That would have been good. Okay, we've got a lot of stuff today. A lot. [00:45:30] So we're probably just going to have to cut out as we go. What episode are we on?
Michael Dyrynda: Forty-seven I think.
Jake Bennett: Okay.