Skip to content

Instantly share code, notes, and snippets.

@mabasic
Last active August 3, 2024 16:44
Show Gist options
  • Save mabasic/21d13eab12462e596120 to your computer and use it in GitHub Desktop.
Save mabasic/21d13eab12462e596120 to your computer and use it in GitHub Desktop.
config_path function for Lumen framework
<?php
if ( ! function_exists('config_path'))
{
/**
* Get the configuration path.
*
* @param string $path
* @return string
*/
function config_path($path = '')
{
return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
}
}

Instructions

Create a file called helpers.php in the app/ directory. Paste the code inside it.

Go to composer.json and add files to autoload so that it looks like this:

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/helpers.php"
    ]
},

Run composer dump-autoload to load the newly created helpers file.

@danielAlbuquerque
Copy link

For "Fatal error: Call to undefined function Tymon\JWTAuth\Providers\config_path()" run "composer dump-autoload" after setting composer.json

@oncelot
Copy link

oncelot commented Apr 18, 2016

perfect thanks

@octaviandavid
Copy link

excellent, thanks!

Copy link

ghost commented Aug 4, 2016

Thank you for this, kind sir.

@rslhdyt
Copy link

rslhdyt commented Oct 7, 2016

thank you!

@benrobey-ewn
Copy link

Why does this even need to be done?

@Otienoh
Copy link

Otienoh commented Dec 2, 2016

In case you are using a Laravel package with Lumen and it requires config_path() function

@kakoma
Copy link

kakoma commented Jun 27, 2017

Works well. Thanks

@linslin
Copy link

linslin commented Jul 5, 2017

Please consider that PHP is an not OS based language. This code will run on any OS like a charm (and not only on nix-systems):

/**
 * Brought by https://gist.github.com/mabasic/21d13eab12462e596120
 */
if (!function_exists('config_path')) {
    /**
     * Get the configuration path.
     *
     * @param  string $path
     * @return string
     */
    function config_path($path = '') {
        return app()->basePath().DIRECTORY_SEPARATOR.'config' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }
}

@david-saint
Copy link

I keep getting an error
as

@leocreo
Copy link

leocreo commented Oct 17, 2017

Thanks man!

@puneetthakur66
Copy link

Thanks for this!

@lzwjava
Copy link

lzwjava commented Oct 31, 2017

Another way to fix it, use LumenServiceProvider instead:

$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);

@bleuscyther
Copy link

Nice

@peterkitonga
Copy link

Thank you man!

@andre-bahia
Copy link

Thank you man, it's works

@shift14wx
Copy link

Thanks a lot!.

@gabriel-silveira
Copy link

Another way to fix it, use LumenServiceProvider instead:

$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);

Thank you! This solved my problem!

@rakeshksrandom
Copy link

it's working for me composer dump-autoload don't forget to run this commend

Migrating: 2017_11_04_103444_create_laravel_logger_activity_table
Migrated: 2017_11_04_103444_create_laravel_logger_activity_table (1.13 seconds)

@mohsenmojadam2019
Copy link

public static function config()
{
if (!function_exists('config_path')) {
function config_path($path = '')
{
return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
}
}
}

@alekaka
Copy link

alekaka commented Feb 18, 2022

Thank you

@nicktencate
Copy link

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment