Fluent helpers, event sourcing, and bartending

Download MP3
Announcer:

This is the Larabell News podcast, your one stop podcast to find out about Laravel related news, tutorials, packages, and more. Here are your hosts, Jake Bennett and Michael Dyrynda.

Jake:

Hello, all you lovely folks out there, and welcome to episode 212 of the Laravel News podcast. My name is Jake Bennett. And, of course, with me as always is my wonderful amazing co host, my co host, the co host, mister Michael Dyrynda. How's it going, Michael?

Michael:

Hello. Hello. I'm going alright.

Jake:

You're looking quite dapper over there, my friend. You have got a serious studio set up now. You've got a soft box. You've got all the lights. You cleaned up the office.

Jake:

You've got all the things here. And it's been a super cool journey to see all the pieces and parts come together. We see in our Telegram chat, like, oh, the stuff's coming in. And then the next day we see here it is. Oh, Michael exhausted.

Jake:

So it's cool. It's cool. So if you're not watching this on YouTube, you should go give it a look. I like it. Michael's put some serious effort in it.

Jake:

It looks it looks nice. I'm still sitting in my kitchen.

Michael:

In the kitchen. Yeah. I, did well, this was we had this conversation the other day where your your problem is not being able to get your hands on the equipment. Your problem is having a space where you can set that equipment up.

Jake:

That's correct.

Michael:

And I said you need to Hunger Games as one of your children.

Jake:

Uh-huh.

Michael:

Just Uh-huh. One of them. And then

Jake:

I quoted Jim Gaffigan. Yeah. And I quoted Jim Gaffigan where he said, like, you know, set my kids down and had a conversation. Said, you know, we love all you, but I'm gonna have give up one of you for adoption because I need a space for my podcasting stuff. And so yep.

Jake:

Yep. So oh oh, boy. It is what it is, though. It's okay. It's okay.

Jake:

The audio works out pretty well.

Michael:

What is the actual video?

Jake:

Surprisingly, not as Yeah.

Michael:

The video and, like, you're using your your iPhone camera, which, like, because when I am.

Jake:

When we record,

Michael:

it gets compressed. So I've always gone

Jake:

Yeah.

Michael:

Yeah. Not that great. But last last North Meet South, I took the the raw video out of the the platform that we're using. And so it actually looks good. So we don't worry about it too much.

Michael:

So doing I'm not committing to doing video just yet. I know that Eric is doing a lot more video for the Laravel News as a whole and I've been dabbling a bit and I've got all the kit set up now. So things look nice. And so I'm not committed to doing video, but I'm committed to the idea of doing video.

Jake:

So you're getting there. It's it's looking it's getting closer every every episode.

Michael:

So yeah, so we there will be a video version of this this podcast that that we

Jake:

put

Michael:

out, whether it's cut up or whether it's just what comes straight out of here. I don't know. But, yeah, there is a video.

Jake:

Well, that should be good. Indeed. Indeed. And I forgot to mention the, the date at the top of the show here. So today is Mar not March 26th.

Jake:

It is April 9th. Michael almost got me again. He tricks me like that. You know, sometimes I get the double update. So we have on the, episode notes here.

Jake:

It is actually April 9th. You correct. I will. It's my fault. Hey.

Jake:

Something that happened. Go ahead.

Michael:

I was gonna say, importantly, we are sponsored once again this week as we will all year long by our friends at Sentry, the performance error monitoring platform that you use, that I use a lot and have used for a long time and that have been long time members of the Laravel community. So stick around. We will talk more about them a little bit later in the show.

Jake:

We will indeed. And before we jump into the show, I wanted to mention real quick. Yesterday was a big eclipse day here in the US. We had, the, total eclipse thing. I wasn't in the path of the total eclipse, but I didn't get to see part of it.

Jake:

And it was it was cool. I mean, I would have had to drive a while to kinda get down to see it. Maybe it would have been worth it. I don't think I've ever seen a total eclipse in my entire life ever. It would have been probably worth it.

Jake:

It's not gonna happen again for, like, 20 more years. Jason Mercurie, however, was, like, 30 miles away from the totality of it. Yeah. And so he drove and went and did it. He said it was totally worth it.

Jake:

So my brother also got some really cool pictures. It was kinda neat. So, yeah. Hopefully, some of you were able to enjoy that. It was a pretty cool pretty cool deal.

Jake:

So, anyway, shall we jump into it? We've got releases, news packages, and more just like the podcast intro says. So let's jump into our releases. Here we go. Laravel 11 non backed enums in database queries and a with schedule bootstrap method in a Laravel 11.1.

Jake:

So we've got a dot release now, Laravel 11 has been something we've been talking about the new hotness and we are now on a dot one release. So this week, they released the 11 dot one with a with scheduled bootstrap method. As I said before, the non backed enums and query builder, SES, which stands for simple email service list management options, which I'm very interested to hear about actually and more. So this is the 1st minor version release since the general availability release of Laravel 11 released earlier this month. Let's get into it.

Jake:

Nuno Maduro contributed a with schedule method to the bootstrap/app. Php file. Okay, let me explain this real quick. The new way that everything is happening in Laravel 11, if you haven't had a chance to play with it yet, is most of the things that you're going to configure, things that you would have previously configured in the route service provider, things that you would have configured maybe even in the app service provider, although app service provider is sticking around, things that you would have configured in your handler dot PHP class. A lot of those things are getting collapsed into this bootstrap/app.

Jake:

PHP. And it's fluent. It's like this fluently defined set of configuration options. So there's, with providers, there's with middleware, there's with routes, there's whatever, you know, the list goes on. But now this one is with schedule.

Jake:

And with schedule, you have a closure and then you can pass into that closure as the first argument, the only argument, a dollar sign schedule, which gives you access to the scheduler. So inside of that closure, then you can say schedule arrow command. And this is just like what you would have done previously in your console kernel. You can now list all of your scheduled jobs right there in your app dot PHP. The other option that you have too is in your console dot PHP file, which is under your routes, routes slash console dot PHP.

Jake:

That has now been, converted sort of to allow you to take any of the things that you have defined in that console. Php, and you can actually chain on the, the methods to those as well. Those commands that you have there, you can do daily, hourly, minute, whatever, and the new Laravel slash Laravel. If you pull in a brand new one, you'll see in console dot PHP after the artisan inspire command, there's an arrow hourly. And so, that's just a little hint there to let you know that by the way, you can do your scheduling in here as well as defining those commands.

Jake:

So now you can do it in your bootstrap/app.php file, couple of different places to do that now, if you care to do it all right in there. So you have one stop, one spot shop to kind of see those different things. Feel free to do that now with this with schedule fluent method on the bootstrapapp. Php file. Okay.

Jake:

List management, options added to the SES mail transport. Aerofil Alam contributed the ability to use SES's subscription management features When you're using SES mail as your driver, you can define the following header in the headers method of a mail message. So there's all these different headers that are specific to emails that are getting sent out. One of those is the XSES list management options, which you can sort of opt into if you're using SES. It is a separate thing you have to opt into, I believe on SES, it's not on by default, you have to turn it on.

Jake:

But this new header automatically enables unsubscribe links in every outgoing email that you specify the contact list and topic of. If the user unsubscribes, then SES does not allow email sending. It'll automatically handle the unsubscribe for you and it will add them to a, like a block list of sorts, right, a suppression list, if you will. This is also really important because Google and Yahoo, created this thing, Yahooogal, right, which is their new sender.

Michael:

Reputation?

Jake:

Not it's it's yeah. What is it? They're rules. They're sender rules. Right?

Jake:

So if you're a bulk sender, if you're sending more than 5,000 messages a day, I think it's required that you have these headers. But in addition, what's really nice is on these different platforms, instead of there being a spam button, it actually has an unsubscribe button up there instead. So they don't have to go down to the bottom of the email, click the unsubscribe. They just look right up there. It's a one single click thing.

Jake:

They click it, it makes a post request to your side, unsubscribes them. And so that's hopefully going to keep down your, abuse sort of complaint rates as well. It should just be it's a simple unsubscribe. It removes it. And, now SES will handle that for you.

Jake:

So very cool that we have that option now, straight inside of Laravel. Okay. Georgio Balduzzi contributed the ability to use non backed enums in database queries. Casting eloquent attributes is already possible. However, using non backed enums with the query builder was not pass, was not possible.

Jake:

So real quickly, a a backed enum is one where you define the enum and then you say at the end, like colon string. I think it's colon string or as

Michael:

string or string or int. Yeah.

Jake:

Yeah. Int. Right. Exactly. And so these, then you have these different backings for those enums.

Jake:

But, if you don't have a backed enums, so if you had an enums status and then you just have 2 cases active and archive with no strings backing this up, you couldn't do this before, but now you can. So, what you can do now is you can say, if you have a user model, for example, you can set your cast, your status cast to cast to that non backed enum. And so that'll just work out of the box for you. So you don't have to do this weird, you know, if you don't want and I'm guessing what it's doing behind the scenes here, Michael, is I'm guessing it's either I wonder how it's I wonder how it's storing it in the database, actually. Queries automatically cast each non backed enum case to the name value.

Jake:

Interesting.

Michael:

Which is the bid

Jake:

on the left

Michael:

of the equal sign.

Jake:

It's the bid on the left. Exactly. And a lot of times, the string on the right is actually the same as the bit on the left. Right? You just have to use name instead of value.

Jake:

Yeah. So interesting. That's kinda nice. So it'll automatically cast each non backed enum case to the name value, the value that you defined that case as. So that's really nice.

Jake:

Cool cool stuff there. Conditional trait added to the con added to context. Now context is something that was released by the, the last time we're talking here. Michael Michael Nobile contributed adding the conditional trait to Laravel's new context facade. So this conditional trait is just something that you can, train on basically so you can have when or unless on top of any of these new things that are added here.

Jake:

So this allows for conditionally setting context and also defining default values when, false or true, depending on the conditional method of when or unless. So that's now added in there. That's everything for 11.1. Of course, you can see the complete list of new features and updates and the diff on GitHub and then the release notes, in the bottom of this post are directly from the change log. So there you have it.

Jake:

Thanks for writing that one up. Paul Redmond, everyone's favorite human.

Michael:

Perfect. Laravel 11.2 was released with a fluent support helper, a context helper, and improved handling of missing database during a migrate operation. So first up, Philo Hermans contributed a Fluid Global helper function when working with multidimensional arrays. This wraps over the existing fluent class that has been in the Laravel framework for quite a while, and the helper gives you the ability to create a fluent object instance from a multi dimensional array. And rather than having to, you know, collect that array and then use methods on the collection, You can reference things directly in a similar way that you would if you've ever used Pest with the expectation API.

Michael:

You can just reference underlying keys as object properties. So instead of doing collect dollar data, our get and then passing a user as a string, You can use fluent dollar data arrow user as a property on the fluent relation. It also then gives you the ability to use GET if you wanted to directly. But there are proxy methods available. So thanks to Philo for that one.

Michael:

Michael Nabil, who contributed the conditionable trait in the previous release, also contributed a convenience context helper function for managing the context facade. Depending on the arguments passed, you can either add to context, get the context object, or retrieve with an optional custom default value. So this is similar to using something like data get, for example, where you can either give me the whole thing or the config helper, you know, get the whole config object, get a specific config object, or get a specific key. So it works very similarly to that, but specifically for the context facade. And also from Michael Nabil contributed support for a default value on the context getters.

Michael:

So previously, if you were to use context colon colon get is user, if that was not found in context, it would return null. Whereas now you can pass a second argument, which would be a default sort of fallback value. So thanks to Michael for that one. Mhmm.

Jake:

Very cool. Those so just to to loop back on these real quick, I think that this is sort of a convention around a couple of these different global helpers. Like you have cache and session, they all work this way, where if you pass an array, it's gonna set the value. If you just call the method by itself, it's going to give you that, that instance, passing just a string value will grab it out or you can pass the second argument, which will be the default. So, yeah, familiar to those of us who've been using Laravel for a while, but if not, worth a quick look over this, or the documentation that'll get you up to speed quick.

Michael:

Yeah. Günther Debrauwer contributed a new assert has chain and an assert doesn't have chain method for testing your Laravel jobs. So this is for testing functionality. You can check to see that chains do or don't get dispatched from code execution. Driest

Michael:

Vints contributed better database failure handling when running the migrate artisan command when a database has not yet been created, as well as updating the migrate fresh command to streamline the process when a database does not exist. So quoting from the pull request, if the migrate fresh command is called while there isn't any database created yet, currently it will fail when it tries to wipe the database. So this PR fixes that by first checking if the migrations table exists and if not immediately going to the migrate command, skipping the DBY part of that operation. And this will invoke the migrate command flow and subsequently will reach the point where the command will ask the user to create the database. And in combination with the second PR, this will offer a more seamless experience for people attempting to install Jetstream through the Laravel installer and choosing not to create the database at that time.

Michael:

So thanks to Drice for that one. And lastly, in this release, Dasun Tharanga contributed an update to the framework Trim Strings Middleware, where invisible characters were not trimmed during a HTTP request, which can cause issues when submitting forms. We'll have links to all of those changes and additions in the show notes.

Jake:

That's, the the database creation wipe handle thing is pretty cool. I actually had a I migrated over to heard for everything. Mhmm. Uninstalled DB engine, uninstalled NGINX, uninstalled all the brew versions of PHP that I had, uninstalled Mailhog, Minio, everything, all the different services I was using and just went all in unheard. Yeah.

Jake:

But while doing that, because I had to wipe out DB engine, I also wiped out all my previous databases, right, that were used for my development stuff. And so, we're going through a bunch of apps doing Laravel shifts. Right? So even the ones that I haven't touched in a long time, I'm having to to test locally Mhmm. Pull a database in it.

Jake:

So when I migrate fresh, it'll say, oh, hey. By the way, you don't have a database there. Do you wanna create it? Yes. I do.

Jake:

That's pretty awesome, actually. And so that's really, really nice. Just quality of life improvement. I love that little stuff. Just little paper cut fixes just makes the developer experience so good.

Michael:

You know, to to the majority of people, you go, ah, that's right. I forgot to do it. I'll just go and create this database. But team Laravel always thinking of of us so that we don't have to worry about that stuff.

Jake:

I know.

Michael:

Just just on the migration from DV engine to heard, if you're using her pro and the managed services aspect of it. If you were to open DB engine, you can right click on the database and go to like the data folder. You can copy, paste that into the same thing in in the herd. And basically, just pick up all of your existing databases and throw them into the herd data stuff and everything works so long as you're working in

Jake:

No way. Are you serious?

Michael:

Yeah. I I said that to myself. I'm like, I have lots and lots of sites. And before I do this, I need to know that it's possible. And yet it's it's just my school handles it.

Michael:

Herd allows you to open the data location. And all I did was copy all of the MySQL data files from the engines location into her location and it all worked seamlessly, started up in all of my database.

Jake:

That's all.

Michael:

Everything was functioning. So it's a tip for those of you playing at home who have been holding out on maybe doing that migration, that as long as you're moving from, you know, my school, I to my school, I my score 5725, although I don't think it's sports 57. So as long as you're going from my score eight to my score, I should have no problems doing that.

Jake:

Good stuff. Yeah. It's it's been good. The the migration over to Herd Pro has definitely been helpful. Okay.

Jake:

Let's talk about Laravel Pint here. So Laravel Pint is a it's part of the Laravel ecosystem. Right? So you think of, like, style ci or, Titan had that, like, one Yeah. PHP CS fixture.

Jake:

That's the idea. Right? That's what it is. Is it's supposed to help keep your code nice and clean and to a, the Laravel standard way of doing REST. So with this week's 1.15 release of LaravelPaint, a new bail flag was introduced.

Jake:

So the bail flag stops LaravelPaint execution on the first failure similar to Pest. So Pest, you can also pass that bail flag and it'll stop on the very first error. Does the same thing now with Pint. So you may may or may not have known this little piece of trivia. I believe Nuno Maduro is the creator of both of those things, Pint as well as, Past.

Jake:

And so, Nuno Maduro actually contributed this, as well in in pull request 261. So it's exciting to see these, you know, it pint isn't, like, dead. It's still getting these continuous improvements, and it's it's I love it. I haven't actually switched over to it, in anything. We just have our we're using style CI still.

Michael:

Mhmm.

Jake:

It's already integrated into our GitHub stuff, and it's just it's working. So not changing it over. But if Stasi ever Cy ever, dies or something like that, it's nice to have another have another option.

Michael:

The bail is nice. There we go. Especially for those of us that are using client inside of CI because it means that you don't have to wait for the entire thing to finish running to see that you've got a if you've got one failure, you may or may not have more, but you don't want, you know, failure right at the start. And for that process to keep running, keep adding to your billable time.

Jake:

Exactly.

Michael:

You have actions as well. So nice. Nice to have that.

Jake:

And that and at that point, you can just kind of go back to, like, oh, locally.

Michael:

I'll run that real quickly. You can do

Jake:

the whole thing locally.

Michael:

Alright. Into the news. First up, a article from Eric Barnes talking about event sourcing in Laravel with the verbs package. So for those of you who don't know, who are familiar, verbs is an event sourcing package for Laravel created by the team at thunk.dev and aims to take all the good things about event sourcing and removing as much boilerplate and jargon as possible. Verbs allows you to derive the state of your application from the events that have, so you can learn about the history of verbs, in a video that we've got here.

Michael:

Daniel Coulbourne on his way back to his home from Laracon India stopped in. He had a layover in Charlotte and he caught up with Eric Barnes and sat down and did a face to face podcast interview. So check that one out. But verbs is great if you're working with applications that need to be auditable, whose schema may change over time with any complex business logic. Right application of event sourcing there.

Michael:

And instead of knowing just the current state of your application, event sourcing allows you to basically know every change that leads to the current state and stores it in the database or in your persistence. And this allows for a more granular understanding of how the system arrived at its current state and offers the flexibility to reconstruct or analyze that state at any point in time. So if you want to learn more about verbs, you can visit the documentation. We'll have links to that in show notes, as well as a link to the video interview between Eric and Daniel. Check it out.

Jake:

Indeed. And and this is something we actually explored on North Meet South web podcast last week as well. I'm gonna be using verbs, in a recent greenfield project greenfield project that we're gonna be taking on. So, we'll try and document that journey using verbs, event sourcing, a little bit more on that show as well if that's something you're interested in hearing about. Okay.

Jake:

We have got Jeffrey Way writing his very first article ever on Laravel News. How is this possible? I guess he's been too busy cranking out content for, Laracasts. But this is the first time, Jeffrey. We're so honored to have you, on the blog and be able to talk about you on the podcast here.

Jake:

So, if anybody doesn't know who Jeffrey Way is, Jeffrey Way, taught me jQuery way back in the day, way, way back in the day when he was at Net Tuts. And he was an awesome teacher then and then launched out on his own when Laravel was, like, in version 3, I think, and started Laracast. Went out on his own and did the Laracast thing and has since obviously become a global phenomenon, just an incredible teacher and, puts out some great content. And so in this article, we're talking about Jeffrey's editor setup in 2024 and specifically his PHP storm setup in 2024. And in the article here, he talks about how, you know, when he was in his twenties, literally every new editor that came out of the market, he was first in line to try it out.

Michael:

Yeah.

Jake:

Right? And so he's like, you know, call it age if you want. I call it contentment. PHPStorm won the IDE war years ago. And let me just tell you how I set it up.

Jake:

So in that spirit, he walks through his general setup and workflow with you, as well as, a lot of different buttons that he prefers to hide, and kind of the minimal approach that he takes when he approaches an IDE. This is one other tip that I think he talks about here, but I have really benefited from, which is hiding tabs, hiding all the tabs, which is really jarring at first. If you're used to working with tabs, like having multiple tabs open across the top of your editor and you get away from it, it actually is scary at first, but it feels really good after that. And so Jeffrey, turned me onto that long time ago, long, long time ago, and I've been doing it since. But that's a weird one.

Jake:

Okay. Let me, let me skip through or skim through a couple of these here. First thing he talks about is color themes. So he's now using the default color theme, right? Just don't mess with it.

Jake:

Just use the default color theme. I haven't gotten quite there yet, but his his, thought process is that each of these other color themes seems to miss some little piece of, the

Michael:

Yeah. Some keywords that

Jake:

it's supposed to be. Yeah. Exactly. So the editor's default things have been battle tested every single possible configuration. And so, that's it.

Jake:

He also sticks with the default font, JetBrains mono, and then he talks about, how he sets up file traversal as far as the search anywhere, line numbers, tab placement, and things like that, how he does that. Then he talks about plugins. And so he does idea VIM, which gives you effectively like a VIM engine so you can do movement throughout your editor using the things that you're used to in VIM. If you want custom UIs and themes, you can install material theme, Nord, or carbon plugins. But one of the big secret weapon plugins that everybody should be using is Laravel Idea.

Jake:

Now Laravel Idea is not built by I don't think I don't think it's built by the JetBrains folks. It does come with a tiny price tag. It's, like, $5 a month. Totally worth it. So Jeffrey goes through a couple of the different things that it gives you, like code generation, automatic validation rules, refactoring, a lot of really, really cool things that, that Laravel idea provides for you.

Jake:

And then, of course, all the different artisan commands that you can run, directly without having to get into your console, which is pretty cool. Jumping down a little bit more, one of the things that he really likes, about having a dedicated IDE as well is the ability to do refactors really easily. There's a whole, workflow built out for doing refactors. So instead of having to use Sublime or Versus Code or something like that where you have to do some find and replace across your entire project, you can just in my case, it's command t, I believe, that opens the refactor, and then I just rename rename it, and it goes all across your entire project to rename everything, which gives you a lot of freedom when you're especially when you're just starting to, like, spike something out. You just kinda name it whatever you want.

Jake:

You don't have to fuss with it too much because, you know, once you're done with it and you're kind of looking over your PR and GitHub, you can be like, I don't really like the name of that. I'm gonna go change it. Yeah. And then you can go change it. So big deal.

Jake:

It doesn't it doesn't take any time at all. Another couple things, integrated terminal, which is nice. You don't have to leave PHP storm. Command 0 for me opens up my terminal. Seamless testing.

Jake:

You're inside a test. You press control shift r. It's gonna run the tests, give you the results right there in your editor, right at the bottom. It's got debugging right in there too with xdebug. If you happen to be using herd, you just pop open the command 5 as debug.

Jake:

Open up that little bar at the bottom. Auto formatting, it will automatically clean up your formatting if you think of, like, Prettier, things like that. It's, command alt l, I think, will do a auto format across everything, and just clean up a controller while you're in there or, you know, whatever you have. It'll just automatically align everything to whatever standard you have set up, And, you don't even have to run Pint to do that. You just go ahead and push the button and there it goes.

Jake:

A lot of good stuff in here. Of course, it wouldn't be complete if Jeffrey didn't have a video course to talk about it as well, so he does have one. It's 2.5 hours long. It'll show you everything that you need to know, how to set it up. So this is more of a, hey.

Jake:

Let me skim over and talk to you about it. But if you wanna set it up just like Jeffrey has, you can go get that free PHP storm course. This is not a sponsored thing. It's free because Jeffrey is awesome. So you should definitely check it out.

Jake:

Jeffrey, from the bottom of my heart, thank you so much for all of the amazing tips and tricks over the years. I would definitely not be the developer I am today without all the assistance that you've given me. So big shout out to Jeffrey Way. Thank you.

Michael:

Oh, sure. Yeah. I saw this. He the he was talking about CSRF. He's got a video out as part of his know what is Laravel or Laravel from Scratch series, whatever it is, will link in the show notes.

Michael:

But I watch this thing and it's incredible to me that after, you know, him teaching for 15, 20 years, that he still has the passion for it, but he still has the ability to get himself into a frame of mind where he can teach beginners in a friendly and approachable manner. And I think that is testament to his extreme ability as a teacher. So hats off to you, Jeffrey. We love everything that you do have done and will continue to do for the Laravel community. On on the debugging aspect of, of PHP Storm, it's nice to have that built into your editor.

Michael:

You're gonna editor, you're gonna catch a lot of things. We're only really gonna catch the things that you're that you're working on. And where something like Sentry comes in is it helps you to identify, debug, and resolve your errors when they happen in production. It'll help you prioritize what errors matter. You can sort things by the number of events, the number of users are impacted, because you know that there's gonna be one that's gonna have thousands of errors because it's in a constantly executed code path, and you've got these things that just crop up every now and then.

Michael:

It'll help you find the root cause of an issue, getting all of the context you need. It'll tell you the environment, the device, the operating system, even the very commit that introduced the error down to the broken line of code and even, potentially, who introduced it. And you can automate everything. It'll keep your entire team informed with customer alerts in Slack. It's 2 way sync for issues with Jira and tracking releases in GitHub or Purcell or Netlify.

Michael:

There's a whole host of other features, including performance monitoring, session replay, code coverage, and more. It works, of course, for PHP and Laravel, but in other things, Next. Js, React, Python, JavaScript, Swift, Go. The list is endless. Check them out at century.io.

Michael:

Use the coupon code, Claravonews, for 2 months free. Thank you, Century.

Jake:

That was probably the best sponsor read I've ever heard. So I I was gonna add something. I don't know if I want to. The only thing I will say is when you said and more, the one thing I was hoping you'd mentioned with the and more is crown monitoring. So if you've got any scheduled jobs like we talked about at the top of the show, that bootstrap/appdot PHP with console or with schedule, it will monitor those for you to make sure that they don't stop running in the middle of the day.

Jake:

I've been debugging something like that today, and I was like, you know what? We need to get this cron thing onto onto Sentry. It's all one stop. Right? It's a single pane of glass, so, really nice to have that in there.

Jake:

Very cool. Incredible. Okay. Well, let's talk about packages, shall we? So fast server side code highlighting with Tempest.

Jake:

So the tempest highlight package by Brent Rose released version 1.0 yesterday, and this is a fast, extensible server side code highlighting for HTML and terminal in PHP. So a lot of the times this is like a front end thing. Right? It gets shipped to the front end and it gets highlighted there. You actually can do this directly in your code.

Jake:

Right? So you have this new highlighter, class that gets imported. Then you can define what theme you're gonna use. You can have light terminal theme, dark terminal theme, whatever you want. And then, with the code given, you can just spit it out, highlighter, parse, you pass in the code, you pass in the type of language that you're using, and it'll spit it out for you given the syntax highlighting that you requested.

Jake:

And so it looks really nice. The built in theme is for a light terminal. And and by the way, I should I should specify here. This is pushing out to the terminal. Right?

Jake:

It's not pushing out to the front end as far as I can tell. For HTML and terminal does both. Let's see

Michael:

here. Yeah. For a Yeah. I think the the wild

Jake:

You're right.

Michael:

Is that you get. Example

Jake:

is the terminal terminal.

Michael:

But yeah, it does. This is why you can replace, you know, the JavaScript based tools that you might have used and things like that with third party services that do it. There's the thing that is like package size that you can use. I know there's a the spicy package uses this thing that runs on this, on the, on the server and does all the highlighting for you. Aaron Francis has got a tool out there as well, which is used on all of the Laravel docs.

Michael:

So we have links all of that in the show notes. But if you want to run all this stuff for yourself, this is a pretty nifty little package that that brands put together. I'm sure a lot of work went into it.

Jake:

It has a lot of, yeah, has a lot of support for different languages and and things like blade as well. Right? So blade's not necessarily like a, it's not like HTML or CSS or PHP. It's Laravel specific, but it's got support for Blade. Yeah.

Jake:

All that stuff. Mhmm. So and you can even add your own languages or extend them. It's it's got a common mark integration, which you can use to highlight code blocks and inline code, things like that. So, yeah, very, very cool.

Jake:

Thanks, Paul Redman, before I add this up. Thanks, Brent for creating this one. Brent Rose.

Michael:

Laravel Stubs is a package that aims to enhance your development workflow in Laravel by providing a set of customizable stubs. You can use the projects Laravel stub facade to manage stubs with the following API. So if you import Laravel stub, you can say Laravel stub from give it a path to a stub, tell it where to go to arrow name, arrow x for extension, arrow replaces arrow generate. So this allows you to take something with some placeholder strings, for example, namespace, open brace, open brace caps namespace. So it does string replacement for you.

Michael:

It allows you to kind of construct your templates however you want to for your Laravel application code, anything that uses the generators and then deals with how to do the replacement for you. Another interesting idea in the package is the download method, which you can use to force a download in a controller if you want to provide stubs for your application. So the package could be an efficient way to provide stub files in your package or application that you want to allow other developers to override with their own customizations. If you wanna get started with the package, we will have links to Laravel Stubb in the show notes.

Jake:

Very cool. This next one's pretty awesome as well. I think you guys might be doing this at work, but you're probably not using this tool to do it.

Michael:

I wish this is a tool. I was doing it.

Jake:

Oh, boy. Right? Wouldn't that have saved you so much time?

Michael:

Certainly would have.

Jake:

The title here is creating preview deployments. So that's when you're in GitHub, when you're in your different, you know, I guess GitLab is the other one. Is that what is GitLab? What was the other one?

Michael:

Yeah. GitLab, GitHub. Yep. Get a bucket. All of those things.

Jake:

Bitbucket. Is Bitbucket still around? People do do you still use that? Yeah. Yeah.

Michael:

Whether or not people can use it, I don't know, but it's still around.

Jake:

Yeah. Right. Yeah. Yep. And so in each of those different, environments, you might have this ability to be able to see a preview of something that you're working on, when a pull request is made.

Jake:

Now I've never had that ability on a Laravel app, but on some different things, like if I have a Nuxt app or something like that, it'll build it for me and, you know, Astro, something like that. But this allows you to create preview deployments on, if you're ready for it, Forge. So the 1st party server provisioning tool, Forge, right, with Laravel? You can now create preview deployments on Forge with Laravel Harbor. So this is a CLI tool that allows you to quickly create on demand preview environments for your app on Forge.

Jake:

So using the CLI, you can then utilize GitHub actions to deploy your branches when a pull request is created, and then it will also tear down that deployment from the server when that pull request is merged. Mhmm. They have an example workflow in GitHub, sorry, in the post here for how you could use GitHub actions. This is taken straight from documentation of Laravel Harbor, which you can find at Laravel dashharbor.com. And then once you configure that CLI to run, any pull request that you make will get updated with comments to the test environment, so that you can see what your preview environment is for a testing feature.

Jake:

So you can see the URL, the database builder URL, you can access the website by clicking on the link. And it has some really cool features like seamless forge integration, automated environment keys. It's ready for Laravel and for Nuxt JS. It has flexible deployment scripts, etcetera, etcetera. Like inertia enables server side rendering for inertia.

Jake:

It can notify Slack and GitHub announcements, from post deployment, and a lot of other cool stuff. So there are a couple of prerequisites, of course, you're gonna need to have a Laravel Forge account and that you're gonna need to have access in your Laravel Forge account to create an API token. So, there are a couple of the prerequisites there, but again, you can check it all out at laravel dashharbor.com. The source code is also available on GitHub as well if you wanna find that in the show notes. And it's free.

Jake:

This isn't a sponsor read, guys. This is crazy. I can't believe this stuff exists and people aren't. Just like out of the goodness of their heart. Hey, here's how we do it.

Jake:

You should do it this way too. Really, really cool stuff.

Michael:

Yeah, this is awesome. Kudos to Mehran and the team that have put this together. We we ended up abandoning the approach that I had built out using Ryan Chandler's forge previewer, somewhere in my annoyance of doing this stuff by hand, I reached out to James Brooks and said, hey, can we just have this as a feature as part of forge? It's amazing that this, of course, popped up now, but we.

Jake:

There you go.

Michael:

We ended up doing all of this stuff in Kubernetes and deploying Docker

Jake:

and

Michael:

so that. So I had a new guy start and handle that project to him. And, and that's that's how we're doing it now. But this this is great if you if you want to do this kind of stuff. So I would I would definitely want to recommend you check this one out.

Michael:

The PDF optimizer package for PHP and Laravel applications is for effortless optimization and compression of PDF files. PDF optimizer utilizes Ghostscript to significantly reduce PDF file sizes. And the PDF Optimizer package can be used in any PHP project whilst also offering a Laravel specific API that streamlines working with PDF file optimization. So if you've ever generated a PDF from some tool, it can get pretty big if you're not careful. So having something to even if it's part of the workflow generator, however, you normally wouldn't put it through this thing which has the Laravel integration.

Michael:

You can say PDF optimizer colon colon from disk open file name to disk put on s3 settings. You can tell it screen PDF or print PDF, Any color conversion strategies, color image resolution, and then say optimize and then the output file name. And it will do all of that for you. So some of the key features of the package is that it offers fluent method chaining. It's got logger support, customization to tailor the optimization process for your exact needs.

Michael:

Valuable integration, of course, which is why we're talking about it. and queue Support. So you can dispatch all of this stuff to the background and have it handled without interrupting your users flow. So definitely check that one out if you ever find yourself needing to crunch in a in a nice way without, you know, getting too many artifacts and and damaging the PDF, I suppose.

Jake:

Indeed. Yes. Yes. Yes. Good stuff.

Jake:

We have a piece of software that does some of the optimization for us, but it's getting old and crusty. And the guy who is supposed to be maintaining it, the guy that we bought it from, he's, like, retiring soon and I'm pretty sure he just stopped answering emails. So it's like, you know, maybe someday we'll start using this and just take it on on our own.

Michael:

Yeah.

Jake:

We've got one more package here to talk about, and this is called bartender, not to be confused with the amazing Mac app bartender, which hides all those icons in the top right corner of your screen, which I also use and love. But this is an opinionated way to authenticate users using Laravel Socialite. So if you have not used Socialite before, it is a Laravel it's a good it's a good different way to handle authentication with OAuth providers. Yeah. Single sign on.

Jake:

Yeah. Right. And this so it supports like Facebook, Twitter, LinkedIn, Google, GitHub, etcetera, etcetera, etcetera, down the line. Right? So these OAuth providers provides a way to be able to connect with those.

Jake:

And then there's a bunch of different drivers, that are available through I don't remember what the name of the site is, but if you go to the documentation, it has

Michael:

a bunch of different providers.

Jake:

I think it is.

Michael:

We have a link to the show notes.

Jake:

That's right. That sounds right. Yeah. That sounds right. But once you have that provider, you're sort of left a little bit to yourself to decide how exactly you want to implement it inside of your Laravel code base.

Jake:

I think they have some tutorials and like some suggestions, but there's nothing that gives you like an out of the box, like, hey, here's how you use Socialite and just put it, put it into your app. So Bartender is basically meant to fill that space. So it gives you a controller, routes, a default implementation for handling that authentication with these different providers. But everything can be almost everything in bartender can be customized. So, using these different configuration conventions that they've set up, you can enable logins by defining these different routes and then configuring the providers that your Apple supports.

Jake:

There's a different, like, when these OAuth providers redirect back, they have to have a place to redirect back to. So unless you wanna create a different controller for every single one of those, what you can do is you can just create this bartender routes and then set up the, different providers inside of this config. And so once the config is set up, then you don't have to create the controllers. It just handles the redirect stuff for you. So it takes care of everything from there.

Jake:

However, you can also extend and customize everything from OAuth redirects and callbacks, user creation and handling, and user direct redirects and flash messaging. So, if you're using OAuth, which I or sorry, not OAuth. If you're using Socialite, which I have used before, you should definitely check this one out. You can learn more about this package, get full installation instructions, etcetera, etcetera. All the things we always say at the end of these, by looking at the show notes.

Jake:

I will say also that typically when you're setting up, these sort of providers, these sort of social logins, you don't typically just do 1. Right? It's typically like you do 3 or 4 or whatever. Yeah. Exactly.

Jake:

And so it does get a bit, onerous to create and maintain all those different connectors

Michael:

and stuff. It's often, like, copy pasting the same thing if you're not

Jake:

It is. Yes.

Michael:

Yeah. Having having it just done for you in an opinionated way. So you don't because it's not all authentication is not really a part of your application. So having someone else's opinions and just and just running with them is generally a good way of doing, you know, having something conventional that you kind of just follow along and then it's just there and you don't have to think about it is a good approach for this kind of stuff.

Jake:

You got it. You got it. Nailed it. Awesome. Alright.

Michael:

Last 2. Two tutorials here. Both of them written by everyone's favorite human, Paul Redmond. The first one is talking about generating code coverage in Laravel using PCOV. So most people, I think, would would be fairly familiar that Xdebug does do, code coverage as well as debugging for your applications.

Michael:

It is a bit heavy, I find in terms of, code coverage. So if you're wanting to do PHP artisan test with code coverage, if you're using test and you want to do code coverage, if you want to use PHPUnit and do code coverage, there's usually 2 or 3 different ways of doing an Xdebug you might already have installed, but it can slow down your test suite when you run it. So it's generally not advised to use Xdebug on your Test Suite. Pcov is specifically for code coverage, and so you might use pcov just to do the coverage reports for your applications. And this tutorial talks about how to set it up, how to install it, how to get it working on a Mac environment, and talks about building HTML reports, configuring it in the HP unit and figuring out what it's doing coverage with.

Michael:

So you can say needs to coverage the app folder, It needs to cover the source folder and things like that. And it allows you to specify nonstandard code paths as well. Gives you lots of different output formats, not Pcov itself, but PSP unit pest under. Now, on top of that, you can send these things to tools like Sentry, for example, which which do handle code coverage analysis and things like that. So wonderful tutorial there from Paul.

Michael:

Check it out. And the second one is a tutorial written by Paul with a video covering, covering the tutorial itself by Eric Barnes. And this talks about creating your own PHP Helpers in a Laravel project. So it talks about creating a helper's file where you might consider putting that, how you would auto load that, whether you do it through composer, JSON's auto load or if you do it is just requiring it in your bootstrap file or whatever and where you would define functions, how you use them and things like that. And so, yeah, we can link to that in the show notes as well.

Michael:

But that is all that we have for this week.

Jake:

That's it, everyone. Thanks so much for hanging out with us. This is episode 212. You can find shown us this episode at podcast.laravel-news.com/212. Reach out to us on Twitter @jacobbennett, @michaeldyrynda or @laravelnews.

Jake:

And, if you like the show, please rate it up in your pod catcher of choice. 5 stars would be amazing. We would really, really appreciate it. Folks, until next time. We'll see you later.

Jake:

Bye

Creators and Guests

Michael Dyrynda
Host
Michael Dyrynda
Dad. @laravelphp Artisan. @LaraconAU organiser. Co-host of @northsouthaudio & @laravelnews. @thenpingme co-founder. Opinions are mine.
Fluent helpers, event sourcing, and bartending
Broadcast by