This is the full transcript of the Laravel News podcast episode #46 - “Laravel 5.5 releases, dynamic templates, and community surveys”
Jake: Welcome to the Laravel News [00:00:30] Podcast, this is episode 46 ...
Michael: It is. It is 46.
Jake: Boom! First time without having to ask you, that's pretty good. Michael is having some internet problems in Australia, imagine that! So we are actually doing this via telegram. Telegram has this new calling feature, which I've used a couple of times, which is really pretty handy. Yeah.
Michael: Yeah it's getting us by.
Jake: I think I've called you at work a couple of times, haven't I?
Michael: Yeah, you have. It's just ... Oh Jake is calling!
Jake: Sometimes it's just more convenient.
Michael: Yeah, absolutely.
Jake: Jake's calling from the U.S. Yeah, so. We're gonna try to make this work, [00:01:00] so we are going to run down a list of a bunch of stuff that's kind of happened. We have Laravel 5555.355.555.11.56 We're talking about all that stuff. So, no dilly-dallying around, we're gonna get right down to it, so now Laravel 55 now includes trusted proxy, and we talked a little bit before the show and Taylor actually mentioned this, on a couple of their podcasts I think, and even at Laracon but do you want to just real quick for me, specifically, [00:01:30] I'm sure for other people as well who don't know what that is, can you explain that real quick for us?
Michael: Yeah, so I guess the main thing for this trusted proxy package, and it is a [inaudible 00:01:38] symphony components is if you are running a load balancer, typically you'll have a https at the low balancer and maybe your servers that sit behind it would served over HTTP, cuz you know that the communication between the low balancer and the web server nodes themselves is secure, so you don't worry too much necessarily about [00:02:00] doing full end to end encryption. So when you're generating your URLs within your Laravel application, it won't know that it's behind the load balancer and so it will generate all of its URLs as HTTP. So your load balancer might actually correct that and redirect everything to https but you've still got that extra hop of hitting the HTTP end point and then https, so what the trusted proxies package allows you to do define an array essentially of trusted proxy addresses that [00:02:30] it knows that it should automatically trust those addresses and it will handle rewriting the URLs for you.
Jake: Well that's pretty handy. Yeah, I can see that being a problem. That would be, I think that would be super annoying and I think that was what Taylor had said too; it's become like a common problem that people are running into, so I said, "You know what? I'm gonna quit answering this question online," and being like ,"just install trusted proxy," we're just gonna install it by default. So in 5.5, it is now included and Chris Fidal I believe is the author of that so thanks Chris! Chris is a longtime Laravel community member, so servers [00:03:00] for hackers, shout out to him, he does some great work. He was around before Forge was and he was like the server guy and so he does good stuff and has a course out there so check that out everyone.
Okay. 5.5.3 released, there's a couple things like 3 or 4 that we're gonna talk about here and then the full change log of course is available in GitHub and then there's actually a post out here on Laravel News that goes through some of it as well. So we're gonna go through just kind of high level here. So there is a [00:03:30] rescue helper, and what this does, this is a global function that helps offer a clean way to return a default value on a throwable exception. So if you have a function that throws an exception, you can wrap this in rescue and then you can return a closure that can catch that throwable and return something instead. So for instance, lets say that you have a guzzle call and you want to catch any exception that's gonna [00:04:00] come out of that and you just want to return an abort 404 with a message to your user or something like that. It would be really easy to do that; instead of doing a tri catch and doing all that, you can basically just say rescue, make your guzzle call in the closure and then as a second closure you would just past app abort 404 and the message. So it basically just allows you to do really simple rescue functions, I suppose right?
Jake: I don't know if there's a better way to explain that, so ...
Michael: Yeah, I believe it's [00:04:30] borrowed from Ruby. I could be mistaken there but I think they've got a rescue syntax in the Ruby language but it's basically a cleaner way, you know you don't have to put the tri and the catch block in there, it's just a two function parameter function so you pass two functions. One is the function that will ... I'm sorry is a callable that will handle your success case and then if that fails, if it throws an exception at any point, then the second parameter is just [00:05:00] what you should return instead. So instead of wrapping the whole thing in a tri catch block, you can optionally use the rescue and you know, whether that is fit for your purpose or you think it looks cleaners, you decide whether or not you want to use that obviously.
Jake: And one thing that the implementation that they kind of site as an example here for where this is really useful is in your tests. So in your tests you may have had before, like you have to set which exception you're expecting it to throw and it's kind of like an annotation, it can be kind of annoying to set that up. I believe that's how it work. [00:05:30] So like, in PHP, I believe as an annotation you put like, "Hey we're expecting this exception to be thrown." And then you run it and then, you know, if that exception does throw than it's good.
So they give a couple of examples here where you just say this [inaudible 00:05:43] equals. You pass in the rescue and then the thing that you're trying to, that you know is gonna give you an exception and then you just pass like a, if it did throw an exception, send through, "Yep the exception was thrown," and then you can just assert that you got that text back. So I would take a loot at the examples, it looks like it's going to [00:06:00] make testing for exceptions being thrown in your code a lot easier and that looks like a really good use case for it. There we go.
Another cool thing in 5.5.3 is the Jason Blade directive so how many times in your code have you ever had to do, in like the footer right, you have script and then you need to kind of assign it a Java script variable. What you'll have to do is, for example equals and then quote and you'll have to do your Laravel kind of like curly braces there but you need to make sure that it's not escaped. Right it's not actually gonna [00:06:30] pass actual Jason in, and then you have to do like Jason in code and then you have to pass through the string or whatever, right? Or sometimes you don't have to do that but if Laravel is already returning it as Jason, whatever.
Well, anyways, there is a really easy way to do that now, which is using a Jason directive that is now provided in 5.5.3, so you just say, "add Jason," and then you pass in the data and it will take care of quoting it and making sure that it's actually rendered correctly to your blade template so check that out, it's pretty cool.
[00:07:00] There's a lot of other things in there that got pushed and it looks like about a list of like 1, 2, 3, 4, 5, 6, 7, yeah 7 or 8 pretty neat things including geo-spacial blue print methods. I'm gonna look that up.
Michael: That would be, like we've got integer and string and text and all that kind of stuff, I guess it would be then functions for the geo-spacial columns that available ... I don't know if they're available in my school but definitely in post-gress ...
Jake: I think they are in my sequel actually, so Titan [00:07:30] had a blog post out there ... In any case it looks like it kind of snuck in there in the 5.5.3 change log so if that's something you're interested in, you know kind of calculating distances using just columns in your my sequel tables, that might be something you want to check out, so go look at the post, you can find it in the [inaudible 00:07:45]
Michael: Maybe I'll have to go and revisit this because I just did a whole bunch of GS facial stuff in the project that I'm working on so maybe I will revisit and refactor.
Jake: Awesome. Yeah. 5.5.5 released and it [00:08:00] released with a new route fall back to help customize your 404 views. So what it looks like is you can specify within any of your groups in your routes, in your web.php. Within a group you can specify a route that is route::fallback and what you can do is you can point that to a controller action and then you can customize the response that gets sent back or you can probably just past through a closure as well and return whatever you wanted and then it looks like outside of that you could just have route fallback [00:08:30] just on the outside, on the very outside and then that would kind of act like your default 404 it sounds like or it looks like ...
Michael: Yeah it's a nicer way than just having like a generic view that would have a 404, see you can obviously override Laravel's default errors by placing a template inside, I think the resources views errors and then you just put a 404 blade in there but you don't really want to start putting conditional logic in there, that you know, if you're inside the dashboard ... [inaudible 00:08:57] route grope do this kind of message [00:09:00] on your 404 page and if it's anything else, you can do that.
Jake: That's beautiful, yeah.
Michael: Conditional checking in your view, you don't really want to do that kind of thing so this allows you to just define, control methods inside your route definitions and then you can handle returning specific error pages, error views from within that controller, which is a little bit cleaner. It separates the logic from your views a bit better.
Jake: Yeah, you know that's really clean. That's really clean. And you could, I suppose, [00:09:30] I wonder if it would take just a ... You could just return like a view, but the things that it does by giving you the ability to send it through to a controller in action is that you actually have access to the sessions, the cookies, the off, all of that stuff. Right? So you can actually return a pretty customized 404 page by sending it to a controller within action, you really have a lot of control over what the 404 response is gonna be. Wow, well that's really nice?
Michael: Yeah and if you need to do any logging of, you know, generating error identifies so that you can [00:10:00] give that back to your user and say, "Hey this error was created," page is not found for whatever reason, you came from this page, you can do all that kind of tracking in there and then give the user some kind of reference if your application is at that lever where you need to track downloads errors so, basically giving you the full access of the framework without just returning a dumb view essentially.
Jake: Yeah, that's really nice. That's really nice. Along with that we also have the include first directive, which [00:10:30] basically will check to see if a view exists and you can pass an array essentially, so you can say, "Here's my array of views that I may want to render. Find the first one that actually exists and render that." So for example, like if you had a blog post or something like that I suppose, is that a good example? Like a blog slug, you could say like, "Hey if this is found, go ahead and do that?" Otherwise ...
Michael: So the way that I thought of when I saw these [inaudible 00:10:58] first is in the web press [00:11:00] basically has it's template hierarchy so you would have a view specific to the slug of that post and you would have one for the category maybe and then you have the fallback to the default blog post view.
Jake: Yeah that makes really good sense.
Michael: But you know at the same time, and you know if you're building an online store for example, you might have a product specific template. You know it's something special, you want to put some custom layout on it, then you could fall back to, again the template for the category that product's in and then towards just the default [00:11:30] product template.
Jake: Yeah, very nice. Very nice and it looks like there's a couple other little things that snuck into this 5.5.5 like there's a -m shortcut to make factory, which also makes model it looks like so if you make factory it will make a model on it as well. Yeah man, this is really like, honestly you just have to read through some of this stuff and just look at it, there's so many things that sneak in under the radar, that you don't even ... You just don't seem them, not everything can be added to the documentation or else it would literally be like, [00:12:00] 3 volumes of documentation so you really just have to pick and choose, so these release notes are really worth looking at thanks to Til for putting these things together.
Michael: Definitely shout out to Til for all the work that he does putting together the change log releases.
Jake: Yeah, and to Paul Rudman as well. Paul Rudman is our, kind of our, practically like full time writer at Laravel news now so he's really doing a great job of documenting all these things and giving some good examples and pulling together the tweaks and stuff too so thanks Paul!
Michael: Yeah, thanks Paul!
Jake: Alright, what else have we got? 5.5.11, [00:12:30] we've got a security fix in 5.5.11, do you want to talk about that a little bit?
Michael: Yeah, so in 5.5.11, which was out I think on the 21st of September was to fix possible timing attacks on the Remember Me Token verification process so there's more information about the specifics of that in the blog post, which we won't go into but if you are on Laravel 5.5 it's best that you upgrade to the latest release.
Jake: Yeah, you can find more details about that on Laravel [00:13:00] News, we'll make sure we put that in the show notes.
Lastly, there was a little bit of discussion about the fact that 5.6 is going to remove the artisan optimize command. So if you're not aware of this, anytime you do like a composer update I think, or a composer install, if you look in your composer.jason file, it kinda has a list of scripts that will run after composer install or composer update are run, and one of those scripts is php artisan optimize, and I [00:13:30] believe what that does is it kind of goes through and does some cashing of things that are loaded, albeit with your app or with composer dependencies. I'm not really sure, I've never honestly really looked into it, have you?
Michael: Not into in depth data, but Laravel basically has an optimized command, which sits on top of the composer's sort of optimized auto loader and that sort of stuff and it was around grabbing all of your dependencies and looking things up in your Laravel application and then just throwing [00:14:00] them in the flat file essentially so instead of traversing the entire vendor tray it would have references to all the of the Laravel requirements directly in that file. So it just sped up learning things and production, but because PHP 7.1 I think improved the way that up code cashing works, the artisan optimized command is essentially not needed anymore.
Jake: Yeah and what's funny is that in 5.5 it actually shipped empty so like the script is still there, it's still run and I think the reason he's doing this is so it doesn't [00:14:30] break deployment scripts for people that are calling it in their stuff, so it doesn't freak out and say, "Oh that's not available, now the deploy is gonna break," right, so it's deprecated in 5.5, it's being removed in 5.6. So, you know, he kind of like graciously gave us a little bit of time to be like, "Okay for this version, it's just empty. There's nothing in there, there's nothing happening when it runs. It's just there." So it's not even being used in 5.5 but it will be gone in 5.6.
Michael: Yeah. I think it's a good sign of maturity of the framework, that the deprecations are [00:15:00] happening now rather than things being removed. So you don't have to worry about things suddenly breaking between ... And I know that Laravel doesn't strictly follow [inaudible 00:15:08] but it's still nice to have a bit of a heads up with those kind of things especially if you say that it's gonna be a far reaching change, if it's gonna break everyone's deployments if something's missing all of a sudden.
Jake: Yep. Yep yep. Okay. Let's talk about dynamic templates with Laravel Blade and view first. This is actually very similar to what we were talking about before, but this is not attached to like, route [00:15:30] groups or things like that. This is actually on the view class. So it's, you know, you've got the directive with the view first now, where you can pass in multiple views, but you also have access to this within your controller as well, so you can say, "return view," and then the next arrow first and then you can pass it an array, so you can handle stuff like in your blade template using a directive or you can handle it in your controller. So I probably should have thrown that in that other [00:16:00] section but in any case, there you go. So it's view and then first and then you pass an array of the views that you'd want to see and then the data has a second parameter and it will go through those and fall back until it finds the one that is available. So anyway, it's a little ... I forgot to mention that before. There we go.
Okay, I've got like 2 minutes left.
Michael: Let's rip through 3 more things than.
Jake: Alright you start, go.
Michael: So the Laravel [00:16:30] 2017 survey is out again this year, so last year we partnered up with Larajobs to put together a survey to see what types of projects people are taking on with Laravel as well as to get some feedback on what the community could be doing better and we had over 1600 submissions with some great insights last year and because of the popularity of that, we have brought it back again this year. The link will be in the show notes. We encourage as many of you as possible to take the survey. It certainly, again, gives us those insights ... I mean I'm [00:17:00] sure that Eric shares some of those with Taylor and I'm sure he's across a lot of them, so it's good to get that kind of community feedback. So help us help you.
Jake: There we go. Alright let's see what else we have here.
Michael: Sublime text.
Jake: Let's talk about sublime text. Sublime text, 3.0 is released. It's been like a beta for a while, long time right? So it's finally been released.
Michael: Yep, so it's final now. The main developer behind it just disappeared for a long time and there was a lot [00:17:30] of angst among sublime text users about whether or not we would see another version of it again. He just came out of the wild one day and was like, "Boom here's the version 3 beta." The beta's been around for I guess about a year. It's pretty solid, I've had no issues with it. It's been very stable. I've certainly had no issues with it since going to the stable training. So yeah check it out. Upgrade your sublime if you have not already, if you're a sublime user. [00:18:00] Or, check it out if you are using something and you think you might want to come back.
Jake: Also if you have a purchased a license after 2013, your license is still valid for version 3, which is pretty cool. So if you've purchased a license any time in the last 4 years, yeah, and if you have one from before 2013, you can get upgrade licenses so you don't have to pay full price for those, so that's very good.
Let's see do we have anything else ... Oh we have top 5 Laravel community editor themes so people are always asking, right like, "Hey what themes is it that you're using, what font are you [00:18:30] using, what is all that stuff?" So our very own Michael Dyrynda, did you make the list my friend? I know you've spent a lot of time recently putting together a theme that matches the documentation style.
Michael: Yeah, I didn't make ... In the post, that theme is tacked on at the bottom ... Cuz I had finished it just after the survey had closed on the editor theme, so we had over 700 responses. 59% of the respondees to that survey were using PHP storm, 36% [crosstalk 00:18:59], [00:19:00] 12% on visual studio code, 8 on atom and 3% on VIM, so that were the top 5 community editors, so for those of you who are playing the Storm vs. Sublime Vs. anything else game, congratulations.
Jake: Storm wins. Woo hoo
Michael: But we do have some great things here that a lot of people are using out in the community so we've got the material theme was the most popular of the themes and that is available for Storm, Sublime text, visual studio code, and Atom, [00:19:30] then Darkula unsurprisingly being that is pretty much the default theme in PHP Storm, a lot of people were using that, there were also ports for Sublime, VS code and Atom. Then there was also Dracula, which is sort of an alternate contrast on the Darkula theme. Monokai, which is the Sublime text default. Jotone, which is the default for Atom, and then Material Peacock and Slime, which were written [00:20:00] by Dale Rees in the early days of Sublime text. Still pretty popular as well and then the Laravel documentation theme, which I spent a bit of time last weekend crafting and a lot of this week ... As I was actually using it, refining and tweaking bits and pieces so, and that's on package control now for anyone who wants to take a look at it. It's pretty nice for those of you who like light themes or for anyone who likes the documentation theme, [00:20:30] it's a pretty close match I think.
Jake: There we go. Last thing, Laracon EU 2017 talks are now on YouTube so go check those out. I think that wraps it up for this show. Michael I'm gonna let you take the outro.
Michael: And thanks Jake for putting me on the spot once again. Thank you everybody for listening to the Laravel News podcast episode 46. You can find the show notes at laravel-news.com/podcast/46 you can also find the transcription for this episode [00:21:00] at laravel-news.com/podcast/46/transcript. If you like the show, obviously feel free to rate us up 5 stars in your pod-catcher of choice. If you have any questions or comments or suggestions for future episodes, feel free to reach us at laravelnews on twitter or on our postman twitter accounts.
Jake: Thanks everybody for listening. We will talk to you in two weeks. See you later. Bye.