Skip to content

Blog

Page 9 of 77 - keep going...

Laravel Log Throttled Users

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.

Sep 1, 2024 2 min read #laravel #security

Laravel Log Incoming API Request and Response

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.

Jul 21, 2024 2 min read #laravel

Generating slugs in factories

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.

Jul 1, 2024 1 min read #laravel #testing

Automatically generate label from enum name

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?

Jun 28, 2024 2 min read #laravel #php

sprintf is the single most valuable tool that you probably aren't using

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.)

Jun 27, 2024 2 min read #laravel #php

Why I rarely use Laravel mailables anymore

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.

Jun 26, 2024 2 min read #email #laravel

Making third-party validation look like your own

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.

Jun 25, 2024 2 min read #laravel

Generate Laravel Seeds Package Idea

When projects don’t have a proper set up of dev data using Laravel seeders, getting started can be kind of tough. And if you can help it, you really don’t want to be pulling data from production. User data is precious and should be protected! So what kind of package or utility could help us here? Let me detail out my thoughts - maybe it’s something you want to build!

Jun 21, 2024 2 min read #ideas #laravel

Git Ignore Without the .gitignore File

As a contractor, I go into a lot of projects. Sometimes these are set up perfectly and other times they need a bit of work for me to be effective and efficient. Some clients are willing to accept updates for tooling, others don’t have the time, budget or ability to accept these updates. So, how can I use my tools - which require configuration files - without editing their project? Actually, git has a nice built-in functionality that will work perfect for this - and it’s not the .gitignore file.

Jun 7, 2024 2 min read #git