unless() is the obvious answer, and it is correct.
But there is also a quieter answer.
when() itself accepts a third callback that runs when the condition is falsy.
There are many reasons why we validate data - whether it’s a Laravel project or any other framework or technology. Sometimes it’s for user or business sanity, other times to keep the application functioning properly. We even do so for security - for both security attacks we know about and hopefully to stop ones we don’t understand.
This is the reason why I reached for validation on pagination requests. This is user input. Just because I don’t understand how it could hurt me doesn’t mean I should ignore it, right?
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: