You cannot use env() outside of config files in production. So this $key = env('API_KEY'); needs to be moved to a config file.
I suggest you read the [!] part here: https://laravel.com/docs/9.x/configuration#configuration-caching
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all
I'm seeing some strange behaviour on my remote server that I'm not sure how to debug. I execute the following code to make an API request:
$my_field_value= '123';
$key = env('API_KEY');
$username = env('API_USERNAME');
$model = MyModel::where('my_field', $my_field_value)->first();
$meta_url = 'https://[url_to_api].com/path/thats/relevant/api?username=' . $username
.'&key=' . $key;
$meta_response = Http::get($meta_url);
dd($meta_response);
When I execute this code locally, I get a 200, but if I execute exactly the same code on my remote server I get a 400. What could be causing this issue, and how can I go about debugging it?
Please or to participate in this conversation.