Saloon, single action controllers, and more
Andrew's newsletter #25: Here's a few interesting things from the last couple weeks you might like.
Introducing Laravel Saloon
Sam Carré is about to release the second version of [Saloon], a PHP package built on top of Guzzle that makes API integrations painless. Using OOP principles, you can create dedicated classes to connect to your third-party and external API services. This keeps your code as DRY as possible and allows for better abstraction and organization across larger codebases.
It’s framework-agnostic by default, but can be used seamlessly inside of the Laravel framework if you want. Bonus points: you can even mock requests for testing, and it comes with OAuth2 support out of the box!
Using single action controllers in Laravel
Last week I published this 6 minute video on using single action controllers in your Laravel applications. You can check it out here, or get a brief summary below:
Single action controllers only have one method in their classes, __invoke(). Instead of the traditional way of using both a controller and method inside your Laravel Route calls, you provide just the class and this single method is what’s called instead.
I find them useful for one-off routes that contain a lot of heavy business logic, but you can convert your entire application to use them if you like that organization better!
Introducing Laravel Pennant
With the recent release of Laravel 10, the team there also pushed out a new first-party package, [Pennant]. It’s a straight-forward and lightweight package to add feature flags to your application!
What’s a feature flag? They’re essentially toggles in your application that allow you to turn on or off parts of your code. You can set them to be always on or always off, using it to essentially roll out new features with zero downtime once they’re ready. Or you can enable the feature to specific visitors based on different factors, including just raw luck (like A/B tests).
Avoiding ref in Vue
When working in the Vue 3 Composition API, there’s two ways you can introduce interactivity to data attributes: ref() or reactive()
If I’m using more than a few refs, my component starts to get messy. So, I end up converting everything to a reactive object called data or state. Besides just cleaning up my code a bit, it also means that I don’t have to use `.value` attributes when getting my reactive data’s current values.
Again, this is just personal preference, but I’ve enjoyed using it in my Vue applications.
Today I learned
Did you know that there’s a few helpful classes and methods included in Composer that you can use in your application? I’m using the one below, `isInstalled()` in a Laravel package to determine if another package is installed on the main app. There’s a few other helpful methods in that class, and you can check them out [here].
That’s it for now! If you want to submit any news, articles, packages, or tutorials, send me a message on [Twitter].