A duplicate ULID that wasn't a collision
Imagine I have this trait that gives any model a ULID-based public_id on create:
Page 5 of 77 - keep going...
Imagine I have this trait that gives any model a ULID-based public_id on create:
Having too many parameters for a method signature is a sign of a method that is doing too much. But, what can be done to make this more readable if you’re forced to stick with it? Let’s see an example using named parameters.
Each API seems to be different. However, there are some best practices that we should all try to follow.
One of those that I really like is the 201 Created HTTP response. If the object is created immediately, you may even return the full object contents.
In some cases, we don’t have the data or don’t want to return the full payload. We can return null with a location header. Here’s how to do that with Laravel.
PhpStorm suddenly stopped recognizing my git repository. I cleared the cache, restarted the IDE, but nothing helped. I jumped to my terminal, ran git from the command line, and everything worked fine there. Confusing, right?
Let me explain why this happened and how I fixed it for good.
AI is everywhere - and it has been for the last months… the last year(s)… I even use it now a lot as a tool for my development. So why haven’t I published AI guidance or written about it at all?
It’s really a simple reason. And it’s not what you think probably. I’m not a hater. It’s extreme love of AI and technology that makes me wait. Let me explain.
I was working on a console command that imports data from a CSV file. Most of the time, I use the same file, but occasionally I need to specify a different one. So I set up an optional argument:
Rector is a powerful tool for automated code refactoring and upgrades. Among its many features, it can enforce coding standards and apply fixes across your entire codebase.
One setting I find particularly useful is ->withTreatClassesAsFinal().
When enabled, Rector analyzes your code as if all classes were declared final, even when they’re not.
When you start your Docker containers, the database container might be “running” before MySQL is actually ready to accept connections. A healthcheck solves this by verifying the service inside the container is responsive.
I love the Spatie Laravel Permissions package. I use it in almost all of my Laravel projects.
When testing, I’ll need to set up users with various different roles and permissions. Usually, I’m using an Eloquent Factory in order to accomplish this.
But it’s a little different when you’re dealing with relationships. Let’s find out how.
In the previous tip, I showed you how to list your dependencies’ licenses. Now let’s make it more useful.