Home > Net >  Laravel: get complete path of file programatically?
Laravel: get complete path of file programatically?

Time:11-06

in my laravel app I have to put the whole path of my file, like this:

$credentialsFilePath = "C:\xampp\htdocs\myapp.com\json\myapp-dda63-firebase-adminsdk-a84ay-19eb8e8646.json"

However this doesn't look so good to me, in production I will have to change the string path for it to work.

Is there a laravel method to do something like this:

absolutePath().'/json/myapp-dda63-firebase-adminsdk-a84ay-19eb8e8646.json'

CodePudding user response:

In Laravel, you can use:

base_path()

CodePudding user response:

First of all, I suggest you to create a variable in php file within the config folder and use that variable all over the applications.

Declare variable and set default path in config variable for Firebase:
'firebase_credentials' => env('FIREBASE_CREDENTIALS', base_path().'/json/myapp-dda63-firebase-adminsdk-a84ay-19eb8e8646.json'),

then use that variable using config() method all over the application. By using that syntax you can set variable value from .env file for different servers i.e. staging, dev, prod

  • Related