Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cookie_good's avatar

how to make .env variable accept multiple scopes

So I looked for an example of this and I couldn't find it on the Web.

Basically, I have the following .env variable:

API_SCOPES=

i have the following api scopes available:

READ_EMAILS, READ_INTERNET_HISTORY, READ_WHAT_YOUR_CLIENTS_DID_LAST_SUMMER

how do I add all three?

I have tried the following:

API_SCOPES=READ_EMAILS, READ_INTERNET_HISTORY, READ_WHAT_YOUR_CLIENTS_DID_LAST_SUMMER

it ended on the white screen of death.

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

You can only have strings in .env, so put a quote around everything in the value if you want to include spaces in the value.

API_SCOPES="READ_EMAILS, READ_INTERNET_HISTORY, READ_WHAT_YOUR_CLIENTS_DID_LAST_SUMMER"
slev1n's avatar

And you can convert these values to array (for example) via /config/*.php, and all variable calls will be returned as array of scopes.

// .env
API_SCOPES="READ_EMAILS, READ_INTERNET_HISTORY, READ_WHAT_YOUR_CLIENTS_DID_LAST_SUMMER"

// /config/app.php
return [
    ...

    'api_scopes' => explode(", ", env('API_SCOPES', '')),

    ...
];

// someCode.php
$api_scopes = config('app.api_scopes'); // ['READ_EMAILS', 'READ_INTERNET_HISTORY', ...]
// can/can't logic with scopes as array

Please or to participate in this conversation.