How to access storage file from .env file in laravel?

by elise_daugherty , in category: PHP Frameworks , 4 months ago

How to access storage file from .env file in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 4 months ago

@elise_daugherty 

To access storage file from .env file in Laravel, you can simply declare a new environment variable in your .env file and then access it in your configuration files or controller. Here's an example:

  1. Declare a new environment variable in your .env file:
1
STORAGE_PATH=storage/app


  1. Access the environment variable in your configuration file or controller:
1
2
3
4
5
// Configuration File
$storagePath = env('STORAGE_PATH');

// Controller
$storagePath = config('app.storage_path');


By following these steps, you can easily access storage file from .env file in Laravel.