You never use env directly as that breaks in production. Put them inside a config file like services.php and load them from there
'Client-ID' => config('services.igdb.key'),
And if you committed to git, be sure to change your keys
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have recently deployed my first site with Laravel forge. It was the Video Game Aggregator series that I've been following with and have come to the end. Now trying to deploy the site I run in to a 500 server error when the access token and auth are in the .env file.
I hard coded the tokens into the HTTP headers rather than calling them from the .env file and the site works fully. I feel like I read it's bad practice to have the keys accessible in the main code so how would I go about fixing this with a live site when everything works locally with .env?
I've attached the example of how it works within the .env locally that is commented out & then how I got it to work.
return Http::withHeaders([ /* Use HTTP client with headers of API tokens from .env */
/* 'Client-ID' => env('IGDB_KEY'),
'Authorization' => env('IGDB_AUTH'), */
'Client-ID' => 'loremipsumXYZ ',
'Authorization' => 'Bearer loremipsum123'
])
->withBody(
IGDB_KEY=loremipsumXYZ #IGDB API Details
IGDB_AUTH="Bearer loremipsum"
Thanks!
@j00rd your above setup with config is correct, but I would use laravel naming convention
'igdb' => [
'key' => env('IGDB_KEY'),
'auth' => env('IGDB_AUTH'),
],
And then
return Http::withHeaders([ /* Use HTTP client with headers of API tokens from .env */
'Client-ID' => config('services.igdb.key'),
'Authorization' => config('services.igdb.auth'),
])
And that should work. Just make sure you redo your cache in production ! php artisan config:cache
Please or to participate in this conversation.