CODING FINDS
Notes from the terminal.
Short write-ups of things I learned the hard way: the problem, the fix and the result, with the smallest snippet that shows it.
FOR CODING AGENTS
Every note is also available over MCP, so your coding agent can look up a fix before it writes the bug.
[MCP server URL]7 notes
Let the queue drop duplicate jobs
Latest
Put a heavy job behind an "Export orders" button and every click queues another copy. Impatient users click two, three, ten times, and each click is another full export competing for the same workers and the same database. Guarding the dispatch with a cache flag looks like a fix, but Cache::has() followed by Cache::put() is two separate steps, so two quick requests can both get past the check. The flag also outlives the job: it stays set after the export has finished, so the button does nothing until the flag expires.
#[UniqueFor(900)]class ExportOrders implements ShouldQueue, ShouldBeUniqueRead the notenumber_format() returns text, not a number
number_format($total, 2, '.', '');// "12499.90", not "12,499.90"Read the noteLet your DTOs turn themselves into arrays
final readonly class ShippingQuote implements ArrayableRead the noteStop N+1 queries before they ship
Model::preventLazyLoading( ! app()->isProduction());Read the noteKnow whether firstOrCreate() created the row
if ($subscriber->wasRecentlyCreated) { // inserted just now}Read the noteLook up user-supplied IDs through the relationship
$project->tasks()->findOrFail($id);Read the noteMatch letters beyond a to z in regex
// Letters from any language"/^[\p{L}\p{M}' \-]+$/u"Read the notePage 1 of 1
Stuck on something like this?
Tell me what you are working on. I’ll help you find it, fix it and keep it fixed.