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.
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.
I’m working with Yajra DataTables in a Laravel project and I’ve ran into a little bit of a headache. They provide their own render() method, which you pass a blade file to as the first parameter. Something like users.dogs.index - and through that mechanism it loads the proper blade for the datatable.
Here’s the problem, though. I can’t get auto complete and I can’t click through on that in PhpStorm. But I want to. Let’s find out how.
When a new terminal opens in PhpStorm on macOS, I was getting a weird error: bash: warning: setlocale: LC_ALL: cannot change locale (en_US-u-hc-h12-u-ca-gregory-u-nu-latn): Invalid argument.. Strange, I use Oh My Zsh with the Zsh shell. Why am I getting that error? Why bash? I could ignore it each time - but I wanted a fix.
I love using Eloquent’s sole() method in Laravel. It throws an exception if the result set is ever more than 1. It means you should only have a sole record. This is usually what I want. I’ve migrated away from firstOrFail() unless I legitimately want the first of a matching set.
But I just found another reason to love using the sole method - it helps add a layer of protection against SQL injection. Let’s find out how.