Discover more from Andrew Schmelyun's Newsletter
TypeScript with Laravel and Vue, the Pipeline class, and more
Andrew's newsletter #26: Here's a few interesting things from the last couple weeks you might like.
TypeScript with Laravel and Vue 3
[Boris Lepikhin] published an article this week that’s all about getting up and started with TypeScript in a Laravel and Vue 3 project. It’s a concise, well-written tutorial aimed at people who have wanted to use the language in their full-stack application, but don’t really know how best to get started.
Follow along with plenty of code examples between both applications, and even sections for code linting and setting up VS Code as well! You can check it out [here].
Laravel’s Pipeline class
There’s an undocumented feature in Laravel that’s gained popularity in a few specific circles and use cases, the Pipeline class. Here’s a quick example of it being used in my upcoming Larametrics V2 release:
Essentially what it does is allow you to pass some kind of payload (a string, array, or in the case above, an object `$event`) through an array of classes. In each class, a method called `handle()` takes your initial variable, or the return from the previous class.
I’m using this pattern to split out complicated workflows into individual “Action” classes that perform a specific job on an incoming piece of data. At the end, I have a returned object that I can use across my application.
A very shiny button
[Alex Widua] showed off this incredible demo on Twitter where they used webcam input and some clever styling to give the illusion of a super shiny button.
The best part is that as a user interacts with it or clicks it, blur marks start getting added that obscure the shinyness even more and act like fingerprints.
If you want to dive more into this demo and see how it works, Alex has posted the code behind it on [GitHub].
Using Laravel’s Bootable Eloquent traits
In case you were unaware, inside of a Laravel Eloquent model class, you can create a static `boot()` method and define events inside of it to hook onto your model’s lifecycle. These include methods like `saving()`, `updated()`, or `deleted()`.
But, let’s say you want to use a trait across multiple different model files. That’s not a problem, you can use the same method. But what if you have a model that already defines a boot method? You can’t use the trait!
Except, that issue’s already been solved. Instead of using `boot()` as the method name in your trait, you can append it with the name of your trait. So for a trait Sluggable, it becomes bootSluggable(), and it performs the exact same way.
Check out a more in-depth explanation with a bunch of code examples in [this article] written by Andy Carter.
Today I learned
This issue’s today I learned comes from the Laracasts Twitter account. If you like the new two-column CLI output from Laravel Artisan commands, you can replicate that in your own command classes as well!
That’s it for now! If you want to submit any news, articles, packages, or tutorials, send me a message on [Twitter].