Rate limiting, Laravel 11 configs, and evolutionary welcome pages

Download MP3
Announcer:

This is the Laravel 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:

Howdy ho, everybody. How's it going out there, Laravel Groupies? My name is Jake Bennett. Of course, with me, as always, is my good friend, mister Michael Dyrynda. How's it going, Michael?

Michael:

Hello. Going well. It's been a sweltering hot week here the last Has

Jake:

it? Yeah.

Michael:

5, 6 days.

Jake:

Yeah. We're just getting we're just getting some of the warmer temperatures. So we're, we're doing well.

Michael:

Well, you just you just run forward. So you're you're about to take this from me. It's it's like the 2nd week of March, and summer has finally arrived.

Jake:

Mhmm. Mhmm. Yes. And, for us, we are just getting started. We are just getting started this summer, and I am loving the temperatures being, like, in the sixties.

Jake:

I suppose, actually, you know what? Raycast has this really nice, let's see here. 60 Fahrenheit. 15 degrees Celsius.

Michael:

Tuesday?

Jake:

16. Yeah. 16 degrees Celsius. About that if I'm rounding up. Yeah.

Jake:

And so it's been really great. It's really great. We're enjoying it and going on bike rides and going to the park and spending time outside, jumping on trampolines, playing kickball, all sorts of good fun.

Michael:

Nice.

Jake:

So, anyway, folks, episode 209 is what we're on. Today is February 27, 2024. Thanks again for, Century sponsoring the show, Sentry.io , for all of your error monitoring needs. We'll be talking about them later on in the show, but thanks to them for sponsoring the entire year of 2024. Yeah.

Michael:

If you

Jake:

haven't checked them out, please do so. They're incredible. I've been using them for at least, boy, I don't know. It's been, like, 8 years probably. Long time.

Michael:

Yeah. Long time. I remember them being OG Laracon sponsors. And, like, we've got them for the whole year. And if you Yeah.

Michael:

Keep on reading the wrong dates, then we're gonna have them for even longer. Because this episode 210 It is March 12, 2024.

Jake:

There it is. There it is. My Notion hadn't updated, and it is March 12th indeed. I put the sponsor reading on the wrong podcast too. I'm just gonna have to paste it in here as well.

Jake:

There we are. Paste it in the correct spot now. Folks, we are professionals. Pay no mind to the man behind the curtain over there. We are consummate professionals.

Jake:

We've been doing this for a while.

Michael:

Several years?

Jake:

My word.

Michael:

Hopefully, Sentry look, Sentry is getting their money's worth. Getting Indeed. Getting 2 weeks of February 27th. So this is all fine and dandy. Let us let us get into the news though.

Jake:

But before we do, hey, today was a crazy day. Am I right? It was a crazy day. Now we're gonna talk a little bit about it just quick. We're not actually gonna cover it altogether, but Laravel 11 is out today as where well as Laravel Reverb, as well as a new version of Laravel Heard, which has got some new features.

Jake:

So all that stuff is gonna be coming up in 2 weeks in the next show. So be looking forward to that. You're not gonna wanna miss it. All sorts of, goodies in that episode, and I will have upgraded at least one of our applications to Laravel 11 at that point using Laravel Shift. So I'll give you my feedback on that.

Jake:

Also, if you haven't checked out Laravel Shift, they're not sponsoring the show, but you should definitely check them out. Anyway, laravelshift.com, Jason McCrearu. He's the man. He might actually I don't know. Is he gonna speak in Laracon AU this year?

Michael:

Don't know. Love to have him. He's a He's awesome to do. Always a great spankos.

Jake:

I was talking to him today. I was like, hey. You should definitely talk to Michael. I was like, he would he would bring you on your lair of a legend status. There's no way he's gonna say no to you.

Michael:

So Anyway We we say yesterday as well. See, I was in turbines about launching the Laracon AU stuff because it was the, quote unquote, same day as the Laravel 11 release. But we had already delayed awake for some various reasons. But, I thought, you know what? It is March, 12th for May before it is March 12th for you.

Michael:

So I'm taking the date. I'm sticking my flight in in there. And so we've we've announced our dates and and that, and there's more information coming in in future weeks. But, yeah, just to ride the Laravel 11 wave a little bit.

Jake:

Indeed. And we've got Laracon India coming up as well. They're kind of

Michael:

There are many ideas in 2 weeks. It's maybe the 27th and 28th?

Jake:

Yep. It's, I think the 23rd 24th March. So a couple of weeks, it's yep. It's

Michael:

gonna be I think you're right. Over there already. You're on one of the, organizers for Laracon EU. So he's over there. He's speaking, I believe, at Laracon India, but I saw that he was tweeting that he's over there already getting a bit of a holiday, and I would say, I think.

Jake:

Yep. So JMac tried to go last year to that one, and he was, not able to

Michael:

go because he was COVID or something, didn't he?

Jake:

Something like that. Something happened with, I think it was maybe his family. I'm not exactly sure. I can't remember if I can't remember precisely, but he wasn't able to go night last year. So he's on the list for this year.

Jake:

So heading over that way, so that'll be pretty cool. So

Michael:

Sweet.

Jake:

Daniel Coulbourne. We got Marcel. Rissa Jackson, who, is hitting the grand slam this year, I think. Right?

Michael:

Grand

Jake:

slam. Yeah.

Michael:

For And Daniel have around the on the grand slam tour, this this completes. And she's speaking at Laracon US, so that will that will complete her 23, 24 grand slam.

Jake:

Pretty cool. Pretty cool. Same thing, man. Should we get to it? Yes, Daniel.

Jake:

Let's get to it. Okay. So here we go. Laravel 10 dot 46. Increment a rate limiter by a custom amount in Laravel 10 dot 46.

Jake:

So 10 dot 46 was released this week with enum validation methods, increasing a rate limiter, and conditional enum validation rules. So let's start talking about the enum validation, gets only, and accept methods. Anton 5360 contributed 2 new methods to the enum validation rule when you don't expect all enum cases to be valid. So, an enum has been introduced in some version of PHP 8, and if you're not using them yet, you should. They are incredible.

Jake:

Really, really enjoy using them. But what you can do is you can validate that a particular value is a, is a valid enum, type. Member. So you member. Oh, enum member.

Jake:

Thank you. Is that the word?

Michael:

That's the word. Okay.

Jake:

So rule do.enum, and then you pass in the actual enum class. And then you can say, I don't actually want to validate that it's any of them. I want to validate that it's only one of these few. Right? So you could say this is the enum I'm interested in, but only validate it against one of these three options.

Jake:

And you can do the same thing using accept. So you could say, I want to validate that it's this email except this one. I don't want it to be this one. Right? So a status enum is a perfect example of where these methods might be practical.

Jake:

After record moves away from new, you likely don't want, don't want to allow a record to return that status again of new. Another example from the pull request, is that once a shipment status is shipped, you wouldn't wanna allow, you sorry. You would only allow it to move to delivered, canceled, or rejected. Right? So, you have a enum that defines all the different states, but you may, in some cases, want to validate that it's only one of a few of those different states.

Jake:

Now you can do that using the enum only or enum except rule additions. Thank you, Anton, for that. Really, really cool. Sebastian Armand contributed the ability to increment a rate limit value by a custom amount. So sometimes a rate limit doesn't map directly to an increase of 1 at a time.

Jake:

Some examples would be something like a limit on the amount of bandwidth that's used or a limit on the number of updates across batch calls where each call could be multiple quote hits. Right? Or a limit on time spent on some operations. So an example of how you could use the increment method to increase the total, by a custom amount and by the way, we're talking about the rate limiter here. Right?

Jake:

So, this is a facade introduced. I don't remember exactly when it was, but it's it's a rate limiter helper here. So now you can say increment by, and then you can specify the key, and then you can pass in as a second value the amount that you want to increment it by. There is also in the documentation a piece on manually incrementing attempts, so you can check that out as well if you're needing to update rate limits. Now and then last, we have conditionally added to the enum rule.

Jake:

Michael Nabil contributed the ability to use the conditionable trait with the rule enum validation rule. So what you can say is, I want to validate that this is one of these types of enums when and then you pass a truthy value. And then if the value is truthy, you can say it should be this type. And if it's not, it should be this type. So, you can give yourself a little bit more logic, without having to break out into a custom rule using that enums.

Jake:

So 2 different things added to actually, there's 3, I suppose, added to that rule enum class. Really, really helpful stuff if you're using enums as types on your model or in your requests, etcetera. Very, very cool. Okay. I think that's all for 10.46.

Jake:

Of course, you can find Shane notes change log between 10 45 and 10 dot 46 on GitHub.

Michael:

Laravel 10 dot47 was released the week of March 6th, which added a new where all and where any method to the query builder and the ability to use sorting flags with the collection sort by many method. First up, the new where all and where any query builder methods were contributed by Musia Moore. This also added the orWhereAll and orWhereAny methods, and the methods can be used to search against multiple columns using or or and logic. So So previously, where we would have to do something like user arrow where and then pass it a closure and then do query where, you know, first name like dollar search or where last name like dollar search or email or phone, you can now do user colon colon where any, pass it an array of columns. So first name, comma, last name, comma, email, comma, phone as the second argument like or equals or whatever you need to do there and then pass it the search.

Michael:

So this is really useful in situations where you want to return some value from your database where any column matches the search string, which is great if you're doing, user filtering or, you know, filtering model records same case. So where you wanna find all of your users where first name is like test and the last name is like test and the email is like test. So you can find all of your test records in the database, I suppose. I think where any certainly would see more immediate use cases for my now the way that I would use it more so than where all, but I'm sure there are still some great use cases for that as well. So thank you to Museum OR for that one.

Michael:

Tim Withers contributed the ability to pass multiple sorting options to the collection sort by method. Before this update, you could accomplish this using multiple callables, but using PHP sorting flags. So you would have to pass an array to sort by and say, you know, function, a, function dollar, a comma dollar B, and then do the comparison with the first and then a second one. So you you're basically going, I want to sort by first the folder name, then a campaign category name, and then the name of the campaign itself. Using the new sorting flags, you can pass sort by as a array of fields, so folder dot name, campaign category dot name, and name as, members of that array.

Michael:

And then as the second parameter, sort underscore natural, which is a PHP constant, single pipe sort flag case. So this allows you to kind of combine all of that stuff into a more terse sort of simpler to digest sort by configuration, rather than having to pass multiple closures and and using the the underlying sort a and b to do your comparisons. So nice contribution there from

Jake:

That's really nice there. Yeah.

Michael:

And lastly, Saeed Hosseini contributed the ability to set the file on timeout property on the queue job that indicates if the job should fail if the timeout is exceeded. So this is simply setting a public file on timeout property on the model, on the job itself. And this is just a boolean flag that you can set to false, and that would prevent your queue listener, or your job from failing when the the time out has been reached. So it would just silently fail rather than throwing a time out exception. So that is all for 10 dot47.

Michael:

We'll have links to all of that in the show notes for you.

Jake:

Awesome. Alright. So not really it's it's sort of in the release front, but it's more along the news front. And Jason McCreary wrote this one up. So let me talk real quick about Jason.

Jake:

So Jason is the creator of Laravel Shift. Laravel Shift allows you to be able to upgrade your applications from previous versions of Laravel to new versions of Laravel. It automates the entire process, creates a GitHub pull request for you where you can check against the diff and make sure that you didn't miss anything or that there's nothing that's going to cause your application problems. It's really, really great. Been using it for forever.

Jake:

But one of the biggest problems that we have when doing these shifts is the config files. Config files can be really, really difficult to upgrade and it can be one of the biggest sources of problems down the road and these very obscure errors if you don't update them correctly. And so this has been something that Jason has actually done really well. He used to not change them at all. He used to just say, hey, by the way, it looks like your config is different than the default.

Jake:

You might want to go check here's the link where the location of the new config is. Go compare it yourself. Then he said, you know what, I'm going to go ahead and do a shift on it, and then I'll just give you I'll let you know sort of explicitly, hey, by the way, we changed these. You might wanna look a little bit more closely at this and did a really good job of updating them for you, which was awesome. But JMac actually wrote this up talking about Laravel 11 streamlined configuration files, and he says that this is one of his favorite new features in Laravel 11.

Jake:

So there was a little bit of a back and forth, that Taylor did here. He said on Laravel 11, we're gonna get rid of all the config files, which was interesting. I was scared because we end up using the config files quite a bit, but only in certain places, only certain ones like database and file systems. We end up using those quite a bit there. And so he's like, hey, we're gonna get rid of all of them and, but you can bring them back if you want using this artisan command to republish them and whatever.

Jake:

And then he was like kind of going back and forth and he decided to, just a few weeks before the release, reintroduce a slimmed down version of the config files in the Laravel default install. But he left this option to remove any files or options you don't need. So Jason took the time to explain to us a little bit how this works and how you can have the smallest list of config files as possible without being confused. So here's the way this works. The way that it works is if your config files were all deleted, you would just get the basic defaults for whatever Laravel has by default.

Jake:

Right? They can add a lot of noise. They're hard to keep updated. They're constantly changing. And so, you know, you really want to make sure that you get this right.

Jake:

If your app has something like a config database PHP file, it's going to get merged with that internal config database PHP file. But what's interesting here is it will merge the top level options for you so you can delete anything that you're not going to customize or anything that you're not going to use. So for example, in like the app dot PHP, you might only want to set the time zone. So in your local config/app.php, all you have to specify is the time zone flag. That's it.

Jake:

You don't have to specify any of the rest of them. You can just delete it. And so you only have that one option there. And the great thing about that is when, when you get shifted, when you're moving up to a new application version, time zone's probably gonna stay there and the rest of them can just change. It doesn't matter.

Jake:

It's gonna change by the framework. And so you don't have to do the work of updating it yourself manually. Right? So the results in configuration is all those app configuration options say the same, like the name, the ENV, the debug, all that stuff just gets set by your dot ENV. Really, really nice.

Jake:

So this works for good top level options, right? Where you're just at the top level. You're not nesting down at all, but then you have things like database connections or file system disks. Well, if you wanted to customize those, you might think to yourself, okay, if I'm going to get into file system dot disks in my config, if I customize one of them, I'm going to have to customize all of them, but you don't. You only have to include the ones that you want to change or your own custom connections for both database connections and file system disks.

Jake:

And then it will do a different type of a merge. It'll do like a recursive merge. So it will overwrite anything that shares the same key or it will add in your custom options if it doesn't already have a key. So for example, in your database dot PHP, if you are already using the my SQL database driver, you don't need to change any of the config options, but you maybe have like a my SQL replica maybe that you wanna do. All you have to do is put in that MySQL replica and that's it.

Jake:

The rest of them can stay out of there. So you can still have really, really slim config files and take advantage of this new config structure, while providing your custom options. And I think this is a great middle ground. Honestly, I really do. I think this allows us to have easier updates while allowing really clear and concise configuration, and only seeing the parts that you care about that are specific to your application, letting the framework handle the rest of it.

Jake:

Because 95% of it is typically the exact same, and you don't need to worry about it. Right? So this is this is really, really awesome, and I'm excited to use this in our applications. I think this is probably gonna be the most it might be the most time consuming one, depending on how his shift goes. However, Jason did say this is the best shift he's ever ridden.

Jake:

He said that. He was like, Laravel 11 shift is awesome. So really excited to see it. And like I said, he's not sponsoring the show, but you should definitely check out Laravel shift if you have any 10, or, I mean, or or older applications. He does a really great job, and he also has a human shift, which he will, basically shift it for you.

Jake:

And I've used that a couple times as well. He's he's great. You should definitely check it

Michael:

out. Yeah. I think key to the success of these these configuration changes will be how easy it is to keep on top of things that are in the framework. Like, if a default changes or a framework provided version changes to something that you might not expect, as long as there's a lot of communication around those things, then, you know, it'll be great. But the thing that's gonna keep you most on track with all of that is your error tracking solution.

Michael:

And with Sentry, it will help keep an eye on all of these changes as you do your Laravel upgrades, not just the config ones. And something that might be of particular interest to you is in moving from version 10 of Laravel to version 11 of Laravel is seeing what the performance impact is. You might also be upgrading to PHP 8.3. You might be doing this as part of your Laravel 11 upgrade and being able to identify any performance issues introduced by the framework using a full end to end distributor trace to see the exact full performing API call and service any related errors would be extremely useful.

Jake:

Awesome. Yeah. There is so much cool stuff that every time I feel like every time I go into entry, there's a new thing that I haven't found yet, that I need to that it needs to turn on. So, like, they've got session recording now, so I'm actually really excited to turn that on. I have a particularly tricky part of our application that is, you know, when you have, like, internal errors, like, if you're making software that's for your internal teams, the good thing is you typically have, like, a ticketing system and you can see those pretty quickly.

Jake:

People surface those things really quickly. But if you have, like, an external application, it's hard to get those, you know what I mean? Get that.

Michael:

Yeah.

Jake:

You can't go sit down with the customer and be like, okay, what happened when you're trying to do this? With the session recording, you can literally see exactly what happened in their session when the error happened, and it'll just give you that little snip. Here's what happened right before the error, and you can see it, actually what they were seeing on the screen. So that's very, very cool. Excited to turn that on soon.

Michael:

Mhmm. You can check out Sentry at sentry.io where if you use the code laravelnews, you will get 2 months for free. Thank you to our friends at Sentry.

Jake:

Thanks again, Sentry. Okay. Let's talk about Tailwind here. So Tailwind, if you don't know what Tailwind is, you've been hiding under a rock. Tailwind is an amazing a, it's a CSS library, but what's our oh, it's atomic.

Jake:

Atomic CSS. Right? Have we used that word in a little bit of time?

Michael:

Utility first CSS framework.

Jake:

There we go. Utility first. Yes. Ala beard. Beard CSS?

Jake:

You remember beard? David Hemphill's beard CSS?

Michael:

Did you

Jake:

ever use that?

Michael:

I did. Yeah. That was

Jake:

that was fun. I used that on one project. Yeah. It was very weird. I remember when first getting started, this is very odd.

Jake:

We're going I think that's

Michael:

that's the taste that utility CSS leaves in your mouth the first time you use it. But as you

Jake:

agreed, you

Michael:

know, as you use it more and more, you find that it's it's just the the quote unquote right approach, in terms of building out interfaces. It's only the quickest way to get started without, you know, having to do a whole bunch of stuff. But, the subject of this post is the announcement of the version 4 alpha release. This version is a very early peek into something that will be an incredible way to write CSS for application web applications. And what we know so far is that how and v four will support or continue to support the tailwind dot config dot j s file to make migrating easier.

Michael:

But the future is a CSS first configuration experience where basically you can configure all of the changes that you need to make using CSS variables. Another feature from the announcement post that caught Paul's eye, who wrote this article, everyone's favorite human, was the 0 configuration content detection. Tailwind will crawl your project looking for the template files and use built in heuristics to find templates. The stable v four release will include support for explicitly defined content parts. But overall, the aim of having less or 0 configuration in v 4 is a big productivity boost.

Michael:

So you don't need a post CSS config file. You don't need a a tailwind config file. You don't need to configure your content globs to, you know, to tell your application or to tell the tailwind compiler that you need to go and look in resources, views, or resources JS or whatever. And there's no at Tailwind directives in your CSS. The v4 engine is a ground up rewrite and takes all of the learning so far to make them faster.

Michael:

It's up to 10 times faster, has a smaller footprint, it's using Rust in expensive and parallelizable parts for the framework. And there is only one dependency in the in the tooling, and that is lightning CSS. I think Adam was saying that it was like an 80 millisecond build for for the tailwind website, and they've got it down to sub millisecond. So they're, you know, busting out the great characters in order to to build their their website now. So there are some impressive and remarkable improvements here.

Jake:

What are you saying? You said that their site takes how long to build?

Michael:

80 milliseconds.

Jake:

What in the heck? That's incredible.

Michael:

That was 10 times faster. Before. That was before. They're now seeing regularly sub one millisecond build times.

Jake:

That's that's doesn't make sense. Nicely done, team. Nicely done, Tailwind CSS team. That's great. That's great stuff.

Jake:

Yeah. I'm excited to play around with this. And, you know, again, kind of on the no config train. Right? Pretty cool.

Jake:

I like that. All the configs go away. Let's just keep it real simple and, make it super

Michael:

easy to get

Jake:

started. Exactly. Embrace the defaults. I like it. I like it a lot.

Jake:

Okay. Hey. We have got a cool little post, by Eric Barnes actually, published by Paul Redmond, but we've got a YouTube video. If you haven't checked out the Laravel News YouTube channel, you should definitely do so. Eric Barnes has been putting out a lot of great content on there, and, he goes through the history of the Laravel welcome page.

Jake:

The Laravel 11 welcome page is really, really cool. So So if you Laravel new, and you get a new version of Laravel 11, you'll see this. It's got a light and a dark theme. Man, it's just got really great clean icons. It's this welcome feel.

Jake:

It's got layer cast, Laravel News. Go Laravel News. It's got it's got the links to to the documentation as well as all the different things that are available to you in the ecosystem is really, really great. So he goes through Laravel 11, Laravel 10, all the way down to Laravel 4.2 and, shows all the different welcome pages that we've had over the years, a little taste in nostalgia for you. So if that's something that's interesting to you, you should definitely check that one out.

Jake:

That's a fun one.

Michael:

This time, an article by Eric Barnes is the ability to integrate Cloudflare Turnstile into your Laravel and Livewire applications. If you've ever wanted to integrate Cloudflare's turnstile, which is a CAPTCHA solution into your Laravel application, this package from Ryan Chandler makes integration super simple. You simply include the Turnstile scripts using the at Turnstile scripts blade directive in the head of your layout file. And after that, you can use the x turnstile component inside of a form, And doing so, in combination with the provided validation rule on the server, will handle all of the validation for you. I think turnstile is using some heuristic based information, basically, because Cloudflare powers, let's say, most of the Internet at this point.

Michael:

So they can tell with a high degree of accuracy if the connection so the IP address or whatever that is making a request to your application is likely or unlikely to be a bot. So you don't have to, you know, train the AI to, you know, which is a traffic light, which is a bike, all of this kind of stuff, all the the squiggly letters that are often difficult to read. This this all just works using Cloudflare magic. The package can also integrate seamlessly with Livewire. Once you have validated the properties specified inside of wire model will be updated with the turnstile token, which essentially verifies that everything is hunky dory.

Michael:

Mhmm. We will have links to all of that in the show notes for you.

Jake:

Yeah. It's got that, like, invisible invisible CAPTCHA sort sort of thing. So it's not even it's not even on the page unless it needs to be. So there's a couple different options with it. You can say, basically, inspect their previous traffic before they get to my page that requires this.

Jake:

And if their traffic has looked legitimate up to this point, don't bother them. Basically, just you shouldn't show anything. In the case that it's sort of got a question mark, it's like, I don't know exactly, then it might show something, and then it'll look at what they how their behavior is where when they're clicking that link to determine, are they bot are they human? You can think of it like, if you've ever gotten one of those Cloudflare pages that asks you to validate your Acumen before it

Michael:

will let you

Jake:

through to a site, if somebody's it that would be the instance in which it would show you this thing. It's sort of like, I'm not sure if this traffic is good or not. Just click this box. Let me see real quick. And then it and then it lets you through.

Jake:

So, yeah, we just recently started messing with this, for our contact page because we were getting a lot of spam. And so, yeah, it's it's really great, and, it's Cloudflare, so it's it's awesome.

Michael:

Nice.

Jake:

Speaking of validation, phone number formatting validation and model casts in Laravel. If you've ever had to deal with phone numbers, you know the pain that this package is trying to solve. Not only phone numbers in the US, like so I've had to deal with that. We created all our own stuff to handle that. But if you hap happen to need to validate phone numbers from different countries, so like USA or Belgium or or the EU or China or whatever.

Jake:

Like, yeah, good luck. Good luck trying to figure that one out. Right? That's what this package does. It makes working with phone numbers in PHP, and Laravel a breeze.

Jake:

Here are the things that it offers. Validation rules, so you can have a validation rule to make sure that it's valid. Attribute casting, so you can say this model rec this model column right here, this is a phone number type. So So when it gets pulled out of the database, it'll cast it to a phone number. And then once you have it in that phone number class, you then have utility helpers and more.

Jake:

So things like cast it to an integer or give me the display version. So let's get the dashes in it or put the plus one on the front or the whatever else it is. Right? That's, that's the whole pitch here. Right?

Jake:

The rest of it is just the code for how you actually implement it. So there's a phone number validation rule. So phone colon, and then you pass in the different countries that you're wanting. The different utilities that are offered are you can have custom formatting. You can format it to a e164, which is like a standardized format.

Jake:

You can format it to international standard RFC 3966, whatever. There's all these different formats that you can use. And it's similar. It feels so much like that money.

Michael:

Mhmm.

Jake:

Is it is there a money package? I know there's a money package. I'm asking. I'm trying to think though,

Michael:

like, you

Jake:

know how you pass in okay. You know how you pass in, like, the actual country that you're dealing with. So you say new phone number, you pass in the phone number and then as a second argument, you pass in the country that you're dealing with. And it'll sort of say, okay, I know what that's supposed to look like. It's supposed to look like this.

Jake:

And then it handles it correctly. Yeah. And I'm realizing while looking at this, there are some really funky different ways that people format phone numbers out there. Here, let me read you one. 012/34.56.78.

Jake:

That's a phone number. How is that a phone number? That's Belgium. What's your phone? What are what are you, like, give me an example phone number, Michael.

Jake:

So, like, in the US, any number that starts with 555 is a not valid number. So if you ever watch a movie, almost always, it's 555 dash whatever. Right? So that's like in the US, it's 555 dash 555 dash 555335334. What is in the in the, in Australia?

Michael:

So a local number is 8 digits and is typically four numbers, four numbers. So four numbers, then a space, then four numbers. If you're if you're dialing interstate, you would put the the area code in front of it in parentheses. So it'd be like 088111 2223 kind of thing. Yep.

Michael:

I think I think the main thing for this package is to kind of normalize what that is. Typically we'll store things in the database using the E164 format, which is essentially like the plus. So if you would be plus 1, and then whatever the number is is for us, it's plus 61. So we would typically store it as just 61, whatever the number whatever the number is. And that kind of just means, for consistency's sake, it's always stored the same way in the database, which means that when you when you split it out again, it will determine based on, you know, the country code plus one needs to be formatted in in a certain way.

Michael:

For for Belgium, you'd be plus 32. So you would store 321, 2, 3, 4, 5, 6, 7, 8. And then it would know that when it comes out that it should should display it as, you know, 0 on to slash 34.56.78, You know, and it kind of just means that you don't have to worry about localization, normalization, all of that kind of stuff because you can infer that from the from the international number. So, yeah, it's I've dealt with a lot of phone numbers. Like, I've dealt with a lot of addresses over the years, and it's it's nice to have some robust tooling to to kind of handle all of this stuff for you now.

Jake:

Very nice. Yep. Awesome. Great package. Let me see.

Jake:

Hold on. Let me let me give credit to who to to whom credit is due here. Hold on. Propagandistas. That's that's the name of the people who created it.

Jake:

Yep. There you go. Propaganistas. Thank you, Propaganistas for Laravel phone.

Michael:

Very good. Alright. Add architecture test to saloon API integrations with lawman. Lawman is a package name. Oh, no.

Michael:

It's great. I like I like it when all of these things kind of lean into whatever the theme of of the thing is. So saloon, obviously, being

Jake:

fun. Yeah. Saloon.

Michael:

Ye, oldie, western saloon. But Lawman is a pest PHP plugin that makes adding architecture test to your application for your API integrations easy with a set of Saloon specific expectations. It is already possible to write architecture test for Saloon with PHP, with Pest PHP, but Lawman aims to make it quicker to write and easier to read. So before, you would have to use, you know, test connector, expect integration connector to extend, Saloon connector to use, like, all of this stuff as strings. Whereas with Lawman, he provides you a bunch of extensions to pest, underlying infrastructure.

Michael:

And that allows you to say, you know, test connector expect and then the the path. And then you have to be Saloon connector to use accepts JSON trait to use always throw on error straight. So it's just it's just giving you readable, method names to all of this underlying functionality without having to, you know, have all of these strings about the place and remembering to put them in or remembering where they are or whatever else when you expand those fully qualified class names. So, thanks to John Purvis for putting this one together. Useful if you are using Saloon and if you are not using Saloon for your API integrations in PHP, I recommend that you check it out.

Michael:

It makes things it's it's kind of sits at a level of abstraction above what the HTTP client is and gives you a nice consistent way of building your API integrations with third party services. So check it out. Shout out to Sam Carrey for putting that one together.

Jake:

Very nice. Okay. Let's talk about JWT tokens, shall we? Does everybody know what JWT? How do you spell JWT?

Jake:

It's the weirdest thing. Right?

Michael:

JW t. I don't know who decided to call it JWT when it's JWT.

Jake:

It's easier than saying JWT though JWT.

Michael:

It's something JWT.

Jake:

Right? And it's actually redo it's, repetitive. Right? JWT token is saying

Michael:

Is it Jason web token?

Jake:

Yeah. Yeah. It's just web token token. JWT JWT tokens.

Michael:

That's it.

Jake:

Anyway, we we move we're moving on here. So Signature Tech Studios Laravel JWT package, makes it easy to generate, consume, and protect routes with JWT tokens in Laravel. Now I remember back in Louisville, Taylor talking about JWT tokens, and I was like, there was this whole thing around JWT tokens and how they were being created, whatever. Laravel had made it really easy to do so, but apparent and I I haven't used them, like, ever. Literally, I've never used them.

Jake:

So I might be the wrong person to be talking about this, but I'm just gonna read the description and act like I know what I'm talking about here. So the package wraps, this other JWT library and provides the following benefits. On top of that package, here they are specifically for Laravel. You get a JWT facade with helper methods to generate and parse tokens. It enforces a minimal set of claims for generated tokens.

Jake:

I'm not even gonna read the options because it doesn't make sense to me. It validates parsed tokens to ensure that the required claims are set properly within the signature present and valid. So I think one of the things it does is it signs these tokens, right, and passes them to the front end. And then when they get past the front end, they get sent back, and the the token that's sent back can then be decrypted and can read off, hey. Here are these different claims that they have.

Jake:

So it's it's almost like, OAuth in a little bit of a way, like, you pass on here the things you should be able to do with this token. It passes the token back, and then you can check to see what what claims they've been they've been issued. Alright. So validates parsed tokens to ensure required claims are set properly within the signature and that they are valid. Has a HTTP middleware to validate a route specific JWT.

Jake:

Network has a request macro to easily access route specific JWT claims. And then you can also build tokens tokens fluently with ease using the provided JWT facade. So it goes through some of the some of the, how you would actually do this. So you set some value, you set a lifetime, you sign it with a key, you say what it's issued by, what it's permitted to do, what claims it has, and then you generate that token. And so it'll do all of that for you inside of your Laravel application.

Jake:

Really nice and simple. It's a fluent interface. So if you're needing to generate JWT tokens, you should definitely check this one out. Seems like it makes it really nice. On the request side then, when you're getting that in, you can parse and validate those tokens, retrieve the claims off of the token, and validate them via a route specific JWT middleware.

Jake:

Again, if this is something you're needing and it's a solution that you've needed to you know, it's a problem that you've needed to solve with JWT tokens, you should definitely check this one out. Seems like it can make your life easier. There we go. Thank you so much to let me see. Hold on.

Jake:

I'm gonna do this again. S tech studio. S tech studio. Signature Tech Studio. Thanks, guys, for putting that together.

Michael:

Perfect. That's it. So we got this quick.

Jake:

That's it, folks. Episode 210. Thanks so much for joining with us. If you wanna find showing us for this episode, you can find them at podcast.laraveldashnews.com/210. Rate us up in your podcaster choice.

Jake:

That would be incredible. We would really appreciate 5 stars. And, of course, if you have any questions, reach out to us on Twitter @michaeldyrynda at @Jacobbennett or @laravelnews. Next episode, we're gonna be talking about Laravel 11, I'm sure in detail, talking about Reverb, talking about Herd, talking about all the new things that Laravel 11 brings along with it. Really excited to be talking about that one.

Jake:

Do not miss it, And thank you, Sentry, so much for sponsoring the show. Michael, give us some give us a sign out. What do you got?

Michael:

Nothing to say except if you are interested in speaking at Laracon US, go and submit your talk. They're still taking submissions. If you're interested in speaking at Laracon AU, speaker submissions are open right now. So do that as well. Get yourself down under.

Michael:

Indeed. Indeed.

Jake:

Alright, folks. Until next time. We'll see you later. 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.
Rate limiting, Laravel 11 configs, and evolutionary welcome pages
Broadcast by