Hi All,
I realize this might not be specific to Jigsaw but does anyone know how to access Netlify Environment Variables during a production build?
I have a Listener that needs to make an API request which requires a key that I can't add to the netlify.toml file (like this):
namespace App\Listeners;
use TightenCo\Jigsaw\Jigsaw;
class GetData
{
public function handle(Jigsaw $jigsaw)
{
$ch = curl_init('https://my-endpoint.com');
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'api_key' => ____GET_API_KEY_HERE____,
])
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
}
}
How can I access the Netlify Environment Variable here it says ____GET_API_KEY_HERE____?
Thanks!
Eric
You should be able to use Laravel's env() helper, which is available in Jigsaw.
Can you try just env('API_KEY') (or whatever your env variable is) and let us know if that works?
OMG, that was easy! Thanks! I was searching everywhere for a solution.
Thanks again!