skip to Main Content

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

$credentialsFilePath = "C:xampphtdocsmyapp.comjsonmyapp-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'

2

Answers


  1. In Laravel, you can use:

    base_path()
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search