Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the laravel way of storing API keys?

Is there a specific file or directory that is recommended for storing API keys? I'd like to take my keys out of my codebase but I'm not sure where to put them.

like image 327
Aakil Fernandes Avatar asked Nov 29 '22 00:11

Aakil Fernandes


1 Answers

You can make your API keys environment variables and then access them that way. Read more about protecting sensitive configuration from the docs.

You simply create a .env.php file in the root of your project that returns an array of environment variables.

<?php

return array(
    'SECRET_API_KEY' => 'PUT YOUR API KEY HERE'
);

Then you can access it in your app like so.

getenv('SECRET_API_KEY');
like image 193
Dwight Avatar answered Dec 05 '22 22:12

Dwight