Menu

The Feature Flag That Was Always Off: env(), config:cache and Typed Config in Laravel
📰

The Feature Flag That Was Always Off: env(), config:cache and Typed Config in Laravel

DEV Community: php·Tuğrul Yıldırım·1 day ago
#cyG1dBuv
#devto#dev#config#file#exit
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.