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

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

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 10 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.

Related Threads:

How to mock storage file download in laravel?
How to overwrite .env file variables in laravel?
How to specify a different .env file for phpunit in laravel?
How to access a package file form laravel controller?
How to ignore the .env file in git?
How to load data from .env file in php?