Property hooks, random packages, and asserting exceptions

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:

Hello, folks, and welcome to episode 213 of the Laravel News podcast. It is April 23, 2024, and we've got a great episode ahead of us. Want to thank Sentry for, again, sponsoring the podcast. They'll be sponsoring the entire rest of the year. Sentry is Laravel, or it's not Laravel specific, but it is error tracking for your applications, and they have an amazing plug in for Laravel.

Jake:

So thank you so much for Century sponsoring. You can check them out at sentry.io. Michael, how's it going, my friend?

Michael:

Hello. Going going well. Keeping very busy at the moment, but, things are things are moving on.

Jake:

Good deal. Yeah. Today, I am at PHP Tek in Chicago. So, I gave a talk today. That was super fun.

Jake:

And, TJ Miller, friend of the Laravel community who had a Laravel Worldwide Meetup talk, a a couple weeks ago, has a talk tomorrow. And then JMac, Jason McCreary, the guy who created Laravel Shift, is up tomorrow as well. He flew in. And one of the speakers actually wasn't able to make it, so he was in Audible. They they called him and were like, hey.

Jake:

Can you can you do talking? So he flew up, and he's doing 2 of them. So Yeah. Crazy crazy stuff. So it's it's awesome.

Michael:

I saw he tweeted that he got the last minute call up, so good on him. And Yes. Unfortunately, that it's not not that much of a of a trip for him to to just duck out there and and have a talk ready to go. So

Jake:

Yeah. He's a professional. Who else who do you else do know that can do that? Just pull 2 talks out. It's that's pretty awesome.

Jake:

So Yeah. So that's been fun, but we've got some good stuff to talk about today starting with releases. Should we jump into it?

Michael:

Let's do it.

Jake:

Okay. Laravel 11.3 was released. So, Laravel prompts have been a thing that we've been talking about a little bit recently. So Jess Archer talked about this at the Laracon in 2023 in Nashville. She created this, Laravel prompts, which allows you to basically have inputs inside of, console.

Jake:

And so, Joe Tannenbaum contributed a text area function to Laravel prompts that allows, accepting of multi line text from a user. Includes also, which is really cool, an optional validation argument as well as a required argument to make sure that the text area is filled out. So when you're, when you're creating this text area, you can, as one of the named arguments there, you just pass in validate, and it accepts a closure and then allows you to, specify what should be true, if this is to be valid. So you could say, like, the string length should be less than 250 or sorry, greater than 250, less than 1000. And if it's not, then you could throw an error.

Jake:

There is documentation for all this and usage details in poll request number 88 in the prompts repository for the implementation. Ma Mahmood Mohammed Ramadan contributed a has any method to sessions, which is a nice improvement when checking to see if any values are in the session. So before, you would have had to sort of pipe a couple checks together. If session has first name or session has last name. And now you can just say if session has any and then accepts an ar an array, as an argument there, to say if first name or last name is in the session, and that will return a truthy value for you there.

Jake:

We also have a new context pull method, which is contributed by renegeuze. renegeuze? I don't know. That's a tough one, folks. It's a tough one.

Michael:

Yeah. René, René, I think their name is.

Jake:

Okay. Alright. Sounds good. René contributed a pull and a pull hidden method to to the context service. And what this will do is, this I think you have this on the session as well.

Jake:

It will pull that context value and immediately remove it from the context. So instead of just getting that value, it pulls it, removes it from the context so that you can use it. And with context, you also have, this idea of setting hidden values, and there's separate methods to grab those values. So, in addition to having pull, you also have pull hidden, which will grab a value out of the hidden context and remove it after returning the value as well. An example use case for this feature might be like capturing the context for database logging and pulling it up because the additional logging, or the additional con the additional context is is no longer needed at that point.

Jake:

You can find all of the changes between the level 11.2 and 11.3 on GitHub, of course. Thank you so much to Paul Redmond, everyone's favorite human, for writing this one up.

Michael:

Nice. Laravel 11.4 was also released, and first up in this release was a intro or a new feature contributed by Nuno Maduro, which is a new exceptions facade. The exceptions facade provides a consistent way to test exceptions in your Laravel applications. It provides an assert reported, reported count, assert not reported, assert nothing reported, throw on report, and throw first reported methods. So this allows you to, where you had previously done something, without exception handling and explicitly caught exceptions.

Michael:

Or if you're using Pest, you can say arrow throws on the end of your it closure, and it allows you to kind of make explicit assertions. And I think I saw someone had tweeted about this in response, you know, why why would you wanna test exceptions? Why wouldn't you just test the byproduct? Sometimes the exceptions are thrown in nested places, and they kind of bubble up to a HTTP exception. So you wanna make sure that the correct exception was thrown.

Michael:

So, definitely check that one out if you're wanting to make assertions against that. devajmeireles is their GitHub handle, contributed the ability to use Boolean style directives without any defined value, in so these are Livewire style directives. So previously, where you would have done something like x hyphen fetch and then wire colon poll, you can, which would generate a div with a wire colon poll. You can now do x fetch wire colon poll. What are we doing here?

Michael:

What is what is different here? I'm not seeing anything different. Are you seeing anything different?

Jake:

I'm looking sorry. I was actually looking at all the, new exception facade stuff that you were talking about just a second ago because I was trying to load up I was exception facade stuff that you were talking about just a second ago because I was trying to load up I was trying to load up the Laravel News page, and I messaged you, like, is this down? Not sure if it's just a really crappy Internet, at the hotel, but Might

Michael:

be a little bit quiet there. Yeah.

Jake:

Yeah. I think so. I think so.

Michael:

So I think previously, this would have generated a wire colon poll equals wire colon poll, whereas now it would just generate a bare wire colon poll attribute floating around on that div. So check that one out. It's just to tidy up the the output HTML, I suppose. Next up, Luke Downing contributed the ability to have reversible form prompts. So these are a group set of prompts for the user to complete.

Michael:

And forms include the ability to return the previous prompts and make changes without having to cancel. So previously, if you made a typo and you hit enter and it went to the next input in your Laravel prompt, you'd have to hit control c, bail out of the whole process, start again. Using this new functionality, you can basically tab forwards and backwards in your, inputs. And so if you make any mistakes, you can go back and and re reenter them nice and easily. So great, great command line, interface, quality of life improvement there.

Michael:

Luke Downing also contributed support for enums on the Collection mapInto method, which allows you to build up enums from an array of values. So mapInto previously would have to take the value from your collection and pass it into the constructor of a class. And so we'd have to go directly into that. But you couldn't do anything with enums, you would have to do this all manually. So this new map into feature, you can now pass it a class string reference to an enum, and it will automatically handle doing this mapping for you.

Michael:

So

Jake:

that's really nice. That's super nice.

Michael:

But, yeah, just again, these these nice little quality of life improvements we love to see. Günther Debrauwer contributed an after query hook to run code after running a query. So this is something that you can chain onto your, query builder methods. These are query arrow after query and pass it a closure that accepts a collection of models and allows you to then carry out some functionality. So if you want more details on what you can potentially do with that, you can check out the description of the pull request.

Michael:

We will have a link to that in the show notes for you. And that is all for Laravel 11.4.

Jake:

Very nice. And so on that, exceptions part there, is this really just a this is just for in testing. Right? Nothing's actually going to change as far as how you are actually throwing exceptions. It's just that Right.

Jake:

Testing for exceptions inside of PHPUnit or Pest or whatever can be sort of a pain in the neck. I think you have to say before you run the thing, this assert exception thrown or something like that or assert exception message. And so this just brings, you the same feeling as working with, those facades by just using exceptions fake and then being able to make assertions after the fact, which just feels which feels good. I think it feels a little bit better. Yeah.

Jake:

So that's pretty cool.

Michael:

Makes it easier. Straight lines it with some of the other functionality as well.

Jake:

Agreed. Agreed. Okay. Let's talk about the news here. Property hooks are getting closer to becoming a reality in PHP 84.

Jake:

So you're gonna have to bear with me on this one, unless, Michael, you know a lot more about this than I do, which is very possible. I've not been keeping up on this one. So I'm gonna read through this. We're gonna work through it together. Property hooks, is an RFC that passed a significant milestone.

Jake:

It got an overwhelmingly positive 34 yeses and only 1 no vote. So that's well above the 2 thirds required majority, that is required to pass. So what are property hooks? So here's the proposal summary from the RFC. It says this.

Jake:

Developers are often using methods to wrap and guard access to properties. There's several several highly common patterns for such logic, which in practice are really verbose to repeatedly implement over and over and over. So alternatively, they may override, the magic get and the magic set, to intercept all reads and writes generically. This they they said this is sort of like a sledgehammer approach that intercepts all of these, undefined and some defined properties unconditionally, and then you have to kind of work in the logic for those yourself. So property hooks provide a more targeted purpose built tool for common property interactions.

Jake:

So let's, let's break that down for a minute. What are we talking about here? We're talking about if you have a class where you have properties defined on it, but you want to handle the retrieving of those properties in some specific way, there's a couple ways to do that, but not any that are necessarily recommended or ones that are not really verbose to implement in every single one of your classes. So this RFC introduces 2 hooks, quote unquote hooks, to override that default get and set behavior of a property. Although they're not included in this initial version, the design includes the ability to support more hooks in the future.

Jake:

So they're inspired by languages like Kotlin and C Sharp and Swift, and the syntax includes 2 syntax variants that resemble short and multiline closures. So this is a little bit code heavy, so we're gonna do our best here. Right? The way that it works then is if you have in your, let's say, you have a user class, and it's going to now implement named. And I'm thinking named here is part of this.

Jake:

What do you think?

Michael:

No. It's I think it's it's just there for for clarity's sake.

Jake:

Okay. I'm sure that

Michael:

makes sense. Space doesn't exist. It's just saying that there has to be some property there.

Jake:

Gotcha. Gotcha. That makes sense. Okay. So as a, as a constructor of this user, we are accepting a first and the last name, and those are both being set as private values, private properties on that.

Jake:

So now you have a public string, and it's passing back or sorry. It's it's here, let me read it for you. Public string, dollar sign, full name. So it's not a public function. It's a public string, dollar sign, full name.

Jake:

And then inside of that, you have some, some brackets and then you have a get what looks like a short closure. Right? It's how you'd have like f n, you know, parens fat arrow over. No, it's you don't have that. You just have get fat arrow, and then you define how you would want to get this new full name property, which again does not exist.

Jake:

It's not a function. It's like a computed property. It's kind of what it feels like. And so you have get, and in this case as federo, this first dot space dot this last. Right?

Jake:

So you're concatenating those 2, the first and the last name with a space in between. And then on the set, which is next after that, this overwritesthe sorry, overrides the right action with any logic that you want. So similarly, set. And then in this case, they're not doing the short closure. They're actually doing a multiline closure here.

Jake:

So, just like you would have with the normal function, you just have a bracket and then another bracket to end it, and then you're gonna return inside of that bracket whatever, whatever you want, except for in this case, you're not returning it. You're actually accepting the values, And then you're going to handle how you want to, push that onto the object, which it's it's a little bit odd. But basically what we're doing here is if we were to set the full name value, it's going to explode it on the space, and then it's gonna set the first and last name of this of this user class, the private values of it, to whatever you passed in. And then in this case, it's also going to also going to set this is modified property as true. So it's you know, I'm doing my very best to read it out here.

Jake:

It's probably going to be better if you go and look at it, but, essentially, what it feels like is you have this computed property, that is now gonna be supported as a first class sort of thing, and you can override the get and the set specifically for one particular, property instead of having to intercept every single get and every single set and then say, if you're setting the full name, do it this way. So that that's pretty good. I think that feels nice. The syntax doesn't require that both hooks always be defined together either. In fact, you can all you can just set the you can just call the set one or you can just call the get.

Jake:

It doesn't doesn't always have to be both of them. So the details for all of this are, spelled out in the RFC. The feature looks like

Michael:

it's going to drop thorough. It is a very thorough RFC.

Jake:

Yep. Yeah. And it's already in the drop pull request if you wanna see yeah. If you wanna see the discussion or progress of the feature, you can go, you can go check it out. So looks really cool.

Jake:

I like that.

Michael:

If you want some more clarity around what it is, we'll obviously have links to this in the show notes. If you're watching this on YouTube, we'll you'll you'll see what Jake is explaining and it will be clearer for you. I think the easiest way to kind of put this into perspective for what it is in terms of a Laravel developer, think of Eloquent attributes. So when you define a protected function full name, which returns an attribute, and then you've got the get and say methods, this is the same kind of functionality, but it's provided as a as a first party like a native PHP piece of functionality. And I think the biggest benefit for that then becomes part of type completion.

Michael:

I know that when you define those attributes as protected methods, most IDEs that I've used will actually hide that. They'll obfuscate that as part of the public API, and you've got to add your own property read or property annotations to to the class to actually get completion on it. So by defining these things as as actual, you know, properties on the class, you will get that type completion automatically. And as you said, you can you can provide get or set separately. You don't have to do them together.

Michael:

You don't have to do comprehensively. The syntax looks a little bit like the match syntax where you've got, you know, the the condition on the left and then the fat arrow and then the and then the resolution on the right hand

Jake:

side.

Michael:

Yeah. But, yeah, the the simplest way I can think of of saying, you know, what these are is think of eloquent attributes. And then that's essentially what we have here as a native PHP implementation.

Jake:

That's a good call. I think you're absolutely right. That's a great way to explain it. It feels, feels a lot more familiar to talk about it that way, since we are on the Laravel News podcast, and so most of us know, what that looks like on the Laravel Eloquent side of things.

Michael:

For sure. Alright. PHP storm 2024.1 has been released with a new integrated terminal, local AI code completion, and more. This new version was released the week of April 10th and includes we've spoken about this previously, I think, on the on the podcast, this new terminal that adds a whole bunch of extra functionality. It looks a bit like, starts with w, I think, terminal.

Michael:

I've lately lost the name of it now, but it gives you some additional functionality. It looks really nice.

Jake:

Is it like okay. Yeah. Go ahead.

Michael:

Combines combines bits and pieces of functionality. Check it out. It's quite useful. There's also, as I said, full line code completion with local AI. Sticky lines are pinned to the top in the editor.

Michael:

There's pest improvements, support for PHPUnit version 11, support for Symfony's asset mapper, improvements to the dd, var_dump, and var_dumper functionality, is checking of vulnerable packages in your composer.json, front end updates, options to scale down the entire IDE, not just, like, the text size, but the actual full IDE itself, which is handy. Static method completion for the class string type in code, sorry, in editor code review and local filtering in the data editor. If you want to learn more about PHPStorm, Jeffrey Way has a, video on Laracast. We talked about this in the previous episode as well.

Michael:

It's an excellent way to set up your editor for a quick and productive workflow in PHP Storm. There's also PhpStorm for Laravel developers on Laravel, which goes into more detail about using PhpStorm for Laravel development. We have links to, of course, all of that in the show notes.

Jake:

The sticky lines is, kinda interesting. I think Eric Barnes had a little video he made about that, where he was kinda, like, scrolling down a class, and he was, like, you know, pinning, like, the name and stuff to the top Yeah. And as it was kinda scrolling up. It was just so it's pretty cool. That that was

Michael:

it. It gives you gives you some context around where you are, especially if you've got, like, a longer class or a longer function and you're scrolling down, it would, you know, it gives you that context of, yeah, I'm in this class, and I'm in this method in that class, and it will scroll out once you, you know, go past the closing price and things like that. So that kind of folding context stuff has been around for for a while, so it's nice to see it in in PhpStorm now as well.

Jake:

Agreed. Yeah. I'm interested to see this in editor code review as well. So I'm wondering if that means, like, if there's a pull request and, like, in editor code review. Like, can I add comments and stuff directly inside there?

Jake:

Maybe. I'm not sure. It's it's sounds interesting. So I'll definitely be downloading this one after the show is over. Alright, we've got another item here, which is automatic blade formatting on save also in PhpStorm.

Jake:

So PhpStorm has really good automatic formatting of PHP files, based on standards that already exist, like PSR 2, PSR 12, Symfony, Laravel, etcetera. You can set that all up in PHPStorm so that I think it's command option l. You press that, and it just kind of formats the file that you're on. However, there have not been a lot of options for consistently formatting blade files in PhpStorm until just recently. So, there have been whispers of blade formatting coming to Laravel Pint, but another interesting option until then is using JavaScript's Prettier Code formatting tool, which I think most of us are probably familiar with.

Jake:

We've heard about this. But there is now a Prettier plug in, blade plug in. So Matt Stelffer has an article on how to set up Prettier on a Laravel app, linting Tailwind class order and more, and that's a really a good primer to formatting Tailwind and blade using Prettier. The gist of the Prettier configuration file is included in the blog post here, just including the new blade included in the blog post here, just including the new Blade plug in as one of the plug ins you're going to do, and then specifying what files it should be concerned with. So star.blade.php are the ones that it should be concerned with, and, and just set the options to set the parser to that new blade plugin.

Jake:

So once you've configured Prettier, you can, go into your PhpStorm settings, navigating to languages and frameworks, then JavaScript, then Prettier, and then you update your settings to reflect, to reflect the following. Paul has it in here as well. Specifically, how you set up again that you're running for on blade.php files, you need to run it through this particular checker. If you want to reformat your code manually, you can also then use the so so what he's doing here is saying, on save, I want to run this Prettier configuration file. That's, that's what he's doing here.

Jake:

So that's, that's nice. But the other thing you can do is you can also say, I want to run this manually, and that's the reform format code action. Of course, everybody has their own different shortcut setup, but depending on what yours is, you can call that reformat code option, and it'll snap that too. So that's pretty nice. I really like that, actually.

Jake:

I actually would also love the the Tailwind one. I don't have that installed. I don't have that set up. That would be really handy one to have set up too. So there you go.

Jake:

Thanks so much, Paul Redmond, for writing that one up.

Michael:

Yeah. I think I think because, like, blade is kind of PHP, kind of not, you know, this this kind of weird syntax that is between worlds. A lot of us kind of tolerate what that looks like, and something else that 4,000,000 developers tolerate is application monitoring software from Sentry. When your app breaks, fix it faster with Sentry. It includes error monitoring, session replay, performance monitoring, and code coverage all within a single interface.

Michael:

It will help you to identify, debug, and resolve application errors. It helps you to prioritize what matters and target issues based on the impact of customers. It'll take you right to the root cause, giving you all the context, environment, device, operating system, even the commit that introduced the error down to the broken line of code and allows you to automate everything by keeping your entire team informed with customer alerts in Slack, two way sync, of issues with Jira and tracking releases from GitHub or Vercel or Netlify. We also include performance monitoring for every developer. You can see what's slower quicker, you can reduce performance issues, you've got browser profiling production.

Michael:

See what your users are seeing, debugging the visual context, protecting your users' privacy, and seeing user frustration signals in the user experience. Get ahead of production issues using Sentry. You can check them out at sentry. Io. And if you use the coupon code, Lara Von News, you will get 2 months for free.

Michael:

Thank you, Sentry, for sponsoring the show.

Jake:

Thank you, Sentry indeed. Long time users, both of us. Super happy with Sentry. If you are looking for an error tracking service, you should definitely check them out as your first choice. Really appreciate you sponsoring the show.

Jake:

Let's talk about a package here. The random package by Stephen Rees-Carter, which if you do not know who that is, he is a really security focused dude in the Laravel world. He's given some really great talks, at Laracons and at Laracon Onlines. And so he's very security focused, and this is this is kind of in that vein. So what this does, this random package, is it generates cryptographically secure random values in a range of different formats through a really simple helper for PHP.

Jake:

So the package was created because Stephen does a lot of, audits, security audits, specifically for it's not only for Laravel, but he that's kind of what he specializes in. But he's got some older code bases he's looked at as well. And and some of the problems that he finds is insecure randomness, usually in places where security is required, oddly enough. Right? So typically people are using like some form of rand, r a n d, right, often injected inside like a, maybe a MD 5 hasher to generate a random hash, and then they'll string shuffle or whatever.

Jake:

And sometimes even, like, a one time password will just be generated using rand between 100,999,999. Right? So just give me a random string inside here. And so the problem is is that Rand isn't actually cryptographically secure, and neither is most of the ones he's talking about here. So his goal though is not just to say, hey, you shouldn't use that and then walk away.

Jake:

Instead, what he's trying to do here is provide an alternative method for what you could use. So, in his package, it is random, dodop with double colon, OTP, so like generating a one time password. And then all you have to pass in there is what length should this one time password be? You know, some, some places use 4 digit one time passwords, other places use 6. All you have to pass in is the length of that one time password you're looking to generate, and then you can send it off to the SMS or email, for that user being able to confirm that they do in fact own that phone number or email.

Jake:

Another thing that you can do is a random string, and this one has a lot more arguments. You can do a length. You can specify a lower or upper bound. You can specify whether it should have, I'm sorry, not a lower upper bound, but lowercase or upper case, I think, if it should have those in there, numbers, symbols, etcetera. And so this will generate a random string for you.

Jake:

It also comes with some nice wrappers for common use cases. Like, instead of having to specify all those arguments, you can just say, give me random letters or give me random token or password or dashed. He's also got another one where if you pass in a collection, I think, or an array, it can shuffle them using a actually cryptographically secure random or shuffle method. So there you go. Very cool.

Jake:

Nice job, Stephen. So thank you so much for providing that one.

Michael:

Nice. Next up, Laravel Stripe Connect allows you or helps you to start your own marketplace platform using Stripe Connect, which allows you to make payments to your recipients directly from your Stripe account to theirs. Using the provided package, you can quickly set up your application's users, connect them to your Stripe account, and start making payouts. By attaching the payable trait in the package, you can onboard users and start sending them payments. So this assumes that the user model represents the recipient, but the documentation outlines how to change the model that is used if a different one represents your recipients.

Michael:

Those of you don't know, Stripe Connect is a platform that kind of allows you to, process payments either on behalf of another seller or on a numb you know, on a on a number of sellers and handles doing split payouts between different sellers. You can do it such that the seller collects the payments and then, you know, you deduct your fees from it as a facilitator of those payments or the platform itself. You as the platform would collect the payments, and then pay out whatever the difference is. So it's a it's a versatile way to act as like a go between end users and your customers being obviously the platform users that are selling products through you. So, if you needed to integrate that into Laravel previously, it might've been a bit tricky.

Michael:

This package will help you do that in a simpler way. We have links to it for you in the show notes.

Jake:

Very nice. Well, we've got one more package here, I think, and it is, no, no, not one more. We've got like 3 more. Here we go. Basset.

Jake:

Basset is an alternative way to load CSS and JavaScript assets. Let's talk about it. It's 2024. I'm calling it. Server side rendering has officially made a comeback.

Jake:

And Laravel, where Livewire, now has 46,000 installs per day, and Ruby on Rails with Hotwire, and Phoenix

Jake:

with LiveWire, and web development in general with HTMX, server side rendering is the way that the world is going right now. Right? So maybe it's time to revisit another practice we've adopted from the JavaScript ecosystem, which is to drop the build step. Who's who's not about that world? Right?

Jake:

I love that. There's been a lot of talk about no build setup in Laravel. Right? I mean, this is a big part of what, Caleb has talked about with Alpine and with Livewire, just getting rid of it. Right?

Jake:

So what about if instead of installing our JavaScript dependencies with the package manager, like NPM, and then bundling them up, what if we were just able to load them directly from the URL? So this is, I think, what this is trying to accomplish. So Bassett is supposed to be a better asset helper for Laravel. So previously to this, you would say link href, and then you say asset, which is going to then grab out, I believe, the versioned, you know, whatever it is, CSS or JavaScript. And instead of that, all you're going to do is you're gonna replace that asset helper with basset, isn't like basset hound.

Jake:

And that's going to gain you some superpowers, such as, assets from CDNs are downloaded to storage and served from there. Vendor assets become possible to load through this. Non public assets become possible to load and it becomes impossible to double load an asset during a request. So in short, Bassett removes all the limitations that asset has, allowing you to load any asset from most locations safely. So that means that in addition to loading in just that that CSS file that you've got in your public location, You can now do it from a storage path.

Jake:

You can do it from a vendor path. You can do it from your CDN, all of that, really, really nice. And so I think that's it. That's the pitch. It's not a perfect loading, asset loading solution, at least not for every project.

Jake:

It's only been around for about 12 months, the author says here. So it doesn't have, like, import maps or things like that. But it, it's proven its usefulness. So thank you, Christian, Tabasattu, for writing this one up. I think he's the author and creator of this as well.

Jake:

So great work. Looks pretty cool.

Michael:

Very nice. Filterable is a Laravel package by Jerome Thayananthajothy that enhances Laravel queries with adaptable, customizable filters and intelligent caching to improve both performance and functionality. The package includes the ability to apply filters based on request parameters with ease, improves performance by caching your queries results, it allows you to easily implement filters that depend on the authenticated user, and the ability to extend the class to add your own filter methods. You can define filter classes at the center of the package as functionality where you can create methods that apply filtering to eloquent queries. The package includes a makeFilter artisan command to generate a filter in your app's app filters namespace.

Michael:

So we will have some examples for you in the show notes, but it's easy to say, you know, something like post colon colon filter. And then you can say, request has, you can query, You can you can use a fluid interface to chain additional filter responses or filter configuration onto that for you. So I have links to all of that for you in the show notes.

Jake:

You, my friend, are consummate professional. You you just roll right through it. No problem. You've got this nails. Don't pat.

Jake:

Oh, kids love them. Alright. We've got I think we are on now. Now we are actually on the final package. Okay?

Michael:

2. The last one.

Jake:

No. No. No. The final package, then we have a tutorial.

Michael:

This is the last

Jake:

one. Yeah. Yeah. Yeah. Okay.

Jake:

Okay. Okay. Microsoft Clarity integration for Laravel. So the Clarity Laravel package lets you easily integrate Microsoft Clarity into your Laravel application. So, the author here, Paul Redmond, says that he himself was not familiar with Clarity before seeing this package.

Jake:

But what it is is it's a GDPR and CCPA, which I think stands for California Consumer Protection Act, which is similar to the GDPR. It's a GDPR and CCPA ready product that you then can embed in your application, and it will capture how people use your site. The main features that it have has here really is that it allows you to include heat maps, session recordings, insights, and Google Analytics integration. It's really easy with this package. You only have to set up a few environment variables and include the blade, the packages blade component, inside of your application's layout file, which is just x dash clarity, double colon, script.

Jake:

That will enable clarity based on the clarity enabled environment variable and the clarity dot PHP configuration file. If setting the environment variable isn't flexible enough, you can also use the enabled property on a component within a variable boolean that you can define. So you can say, it should be enabled on these particular pages, or it shouldn't be enabled on these particular pages. So while you could easily integrate the clarity embed code in your application directly, this package takes care of all of that for you. You don't have to worry about setting it up.

Jake:

You just install the package and then away you go. So you can start collecting data pretty quickly, within minutes. Right? You can learn more about the package, of course, the source code, which we'll have linked up in the show notes. And you can also learn about more about Clarity from the Microsoft Clarity documentation as well.

Jake:

So pretty cool stuff. Thank you so much for writing that one up, Paul. We've got a tutorial, and then we're done. Mister Dorinda, what do we got in the tutorial side of things?

Michael:

The one tutorial we spoke about the new exception facade earlier in the show, and we are not gonna leave you hanging. Mr Paul Redmond, everybody's favorite human, has a tutorial on how to use the new exceptions facade to make assertions against your exceptions in Laravel tests. So your homework at the conclusion of this episode is to go and read that tutorial and put into action this, this new piece of functionality in your application tests.

Jake:

And you know what? Some people so here's, you know, here's what I'll say. There has been some talk. I've heard some people recently be like, you know what? Like, people are just upgrading too quickly, and I get it.

Jake:

I get it. But also this is why this right here, this is why we try and keep ourself up to date because you never know when that next feature is going to come out where you're like, like, oh, man, that's actually really helpful. And if you're staying up to date, you get all these free tools, these free goodies as soon as they're released. And

Michael:

it's just awesome. Functionality in Laravel 10.

Jake:

You're not. Not for you. You're not. And, like no. Not not for you.

Jake:

It's not getting backported. But here in in a certain sense, I almost feel like the Laravel team is, like, on my team. You know what I mean? Like, Tara Taylor is paling ping all these really smart, people to build these features, and it's like, I get to use them. And, you know,

Michael:

I don't know.

Jake:

That that's for me. That's why we stay up to date.

Michael:

We we don't even have to we don't have to make these features. We just get to use them

Jake:

for free. I know.

Michael:

We just get to

Jake:

use them. Yes. Exactly right. Exactly right. So that's my pitch.

Jake:

That's my pitch for staying up to date. So there you go, folks. Hey. This has been a good one. I've really enjoyed this.

Jake:

A lot of cool stuff today. Episode 213 in the books. If you'd like to find show notes for this episode, you can find them at podcast.laravel-news.com/213. Rate us up in your podcatcher's choice. Five stars would be incredible.

Jake:

And if you have any questions or comments, hit us up on Twitter @michaeldyrynda , @JacobBennett, @laravelnews. Hey, folks. Until next time. It's been a good one. We'll see you in a couple weeks.

Creators and Guests

Michael Dyrynda
Host
Michael Dyrynda
Dad. @laravelphp Artisan. @LaraconAU organiser. Co-host of @northsouthaudio & @laravelnews. @thenpingme co-founder. Opinions are mine.
Property hooks, random packages, and asserting exceptions
Broadcast by