Show Alpine Element After Delay
Showing and hiding AlpineJS elements on click or other actions are pretty easy. But what if you just wanted to show the element after a little bit of a delay with no user interaction? We can do that easily!
Page 8 of 76 - keep going...
Showing and hiding AlpineJS elements on click or other actions are pretty easy. But what if you just wanted to show the element after a little bit of a delay with no user interaction? We can do that easily!
There’s a common design pattern on a lot of websites to alter the header when the user scrolls down. A lot of times this is simply some sort of handler that adds a class (or removes it). (There are other complex, arguably ‘better’ solutions with IntersectionObserver - but that’s not the point of this article.) Let’s take a look at a very simple version of a script that watches for scroll and adds/removes a class on the body. Then, let’s make it better - and learn while we do it.
I love writing in Markdown - and offering that functionality in WYSIWYG editors for our users. But, it just seems so complicated to try to show markdown in Laravel blade files. So, I made a quick anonymous component that makes this easier.
You’ve got Laravel throttling set up on authentication, password reset and other sensitive endpoints. But, how do you know this is actually working to stop people? Or what if you either want to admonish bad users or proactively reach out with support to help them? Perhaps you might want to log your throttled attempts. It’s pretty easy.
There are packages out there to add logging to the HTTP client in Laravel for outgoing requests freely available. Those are great, but what about if you’re providing an API - and you need to log incoming requests and responses? There’s not a single place to do that - or is there? Let’s look at a middleware to log our incoming requests and responses.
Normally, I would generate a slug for an Eloquent model with an observer or an event. The creating event can verify if the slug field is filled, and if not, use the Str helper to add it to the current creation payload. Pretty cool.
I was so happy when I saw that Enums had finally come to PHP. Up until this time, I had been faking this sort of thing with constants on interfaces.
The times are changing, and I’m here for it.
In most Enum declarations, you’ll find a simple set of key value pairs, or in the PHP language, a name and a value. The name allows you to reference it in your code. The value usually is stored or passed around as data.
So, what happens when you need to display something like a text label to the user?
A few years ago, I wrote a gentle introduction to sprintf. For those who read it, their code quality, speed and readability increased dramatically (I hope…).
But why would you even want to use sprintf? Its syntax looks pretty complex and we already have solutions for most of the things it solves. (This is how I felt about regular expressions early in my career. I have since learned the error of my ways.)
Joel and I were working on a project that had a number of business situations that the owners wanted to know about. They asked if they could get emails when these things happened. (Like a user flagged an article. Someone’s auto-renewal failed. Etc.) There were a number of mailables in the project when I joined.
I hissed. I boo’d. Joel asked me why I was being such a cranky boy.
You’re a professional, so you write thorough and secure validation for every one of your forms. You confirm values are in the proper shape and type, and when appropriate, even query the database with rules like exists. But what do we do when we aren’t the owners of that information? Let’s dig in.