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

Ligonsker's avatar

How would you create test/prod condition for the same disk name?

Hello,

If I have 2 different network filesystem disk paths for prod and test, how would you configure it?

For example, the test path is \\some_network_location\test\my_disk, and the prod path is \\some_network_location\test\my_disk, should my /config/filesystems.php file look like this:

switch (config('app.env')) {
    case ('prod'):
        return [
            'disks' => [
                'my_disk' => [
                    'driver' => 'local',
                    'root' => '\\some_network_location\prod\my_disk',
                ]
            ]
        ];
    break;

    case ('test'):
        return [
            'disks' => [
                'my_disk' => [
                    'driver' => 'local',
                    'root' => '\\some_network_location\test\my_disk',
                ]
            ]
        ];
    break;
}

or a different way? In the above way the file would basically be a copy of the same values just swapping the word "test" with "prod" everywhere. But maybe there's a more elegant way?

Thanks

0 likes
4 replies
DhPandya's avatar

@ligonsker This might help you.

$env = config('app.env');
return [
    'disks' => [
        'my_disk' => [
            'driver' => 'local',
            'root' => "\some_network_location\$env\my_disk",
        ]
    ]
];
1 like
Ligonsker's avatar

@DhPandya thanks! Yes it also works, in my case in reality though there may be exceptions where it's not always the difference between "test" and "prod". Sorry I didn't mention because I just realize that some of the older code was messed up and mixed some weird names. OF course if I can refactor it then I will try your solution. Otherwise - is there another way for this case?

Snapey's avatar
Snapey
Best Answer
Level 122

don't you have a different env file for tests? or are you talking about a test installation.

If you have a test installation then it should be done through the env file

If you put logic like you proposed in a config file, it can no longer be cached

I would;

'disks' => [
     'my_disk' => [
         'driver' => 'local',
         'root' => env('LOCAL_DISK_PATH', '\some_network_location\prod\my_disk'),
     ]
 ]

and then on test installation, the env file can contain

LOCAL_DISK_PATH= '\some_network_location\test\my_disk',
1 like

Please or to participate in this conversation.