The deploy went out on a Friday afternoon. Tests were green, staging looked fine, and nobody touched the .env file. On Monday, finance noticed that no invoices had been sent to the e-invoicing provider since Friday.
The sync job was running. It just decided, every single time, that the integration was disabled.
The cause was one line in a service class, and one new line in the deploy script. If you have ever called env() outside a config file in Laravel, this story is about your code too.
The problem: env() works until the day it doesn't
Here is a simplified version of the code. It looks harmless:
<? php
namespace App \ Services ;
class InvoiceSync { public function enabled ( ) : bool { return ( bool ) env ( 'INVOICE_SYNC_ENABLED' , false ) ; }
public function batchSize ( ) : int { return ( int ) env ( 'INVOICE_SYNC_BATCH' , 50 ) ; } }
Enter fullscreen mode
Exit fullscreen mode
It worked for months.…