Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@rizkytahara

This comment has been minimized.

Copy link

@rizkytahara rizkytahara commented Jan 22, 2016

Hi, may I know where this file should be put and how to load it?

@di3

This comment has been minimized.

Copy link

@di3 di3 commented Jan 24, 2016

create "app/Support/helpers.php"
and add this function

modifty the composer.json file. add the following to your autoload section:

"autoload": {
    ...
    "files": [
        "app/Support/helpers.php"
    ]
}

then you can run:
composer dumpautoload

and helpers will load automaticaly every time

@marcoacm

This comment has been minimized.

Copy link

@marcoacm marcoacm commented Feb 16, 2016

This is not working for me, I keep getting
Fatal error: Call to undefined function Tymon\JWTAuth\Providers\config_path()

Any ideas?

@imbhupendra41

This comment has been minimized.

Copy link

@imbhupendra41 imbhupendra41 commented Mar 4, 2016

i am getting the same problem and it keep getting
Fatal error: Call to undefined function Tymon\JWTAuth\Providers\config_path()
Have you got any solution

@danielAlbuquerque

This comment has been minimized.

Copy link

@danielAlbuquerque danielAlbuquerque commented Apr 12, 2016

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

@oncelot

This comment has been minimized.

Copy link

@oncelot oncelot commented Apr 18, 2016

perfect thanks

@octaviandavid

This comment has been minimized.

Copy link

@octaviandavid octaviandavid commented Jul 30, 2016

excellent, thanks!

@ralphstodomingo

This comment has been minimized.

Copy link

@ralphstodomingo ralphstodomingo commented Aug 4, 2016

Thank you for this, kind sir.

@rslhdyt

This comment has been minimized.

Copy link

@rslhdyt rslhdyt commented Oct 7, 2016

thank you!

@benrobey-ewn

This comment has been minimized.

Copy link

@benrobey-ewn benrobey-ewn commented Oct 16, 2016

Why does this even need to be done?

@Otienoh

This comment has been minimized.

Copy link

@Otienoh Otienoh commented Dec 2, 2016

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

@kakoma

This comment has been minimized.

Copy link

@kakoma kakoma commented Jun 27, 2017

Works well. Thanks

@linslin

This comment has been minimized.

Copy link

@linslin 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

This comment has been minimized.

Copy link

@david-saint david-saint commented Aug 30, 2017

I keep getting an error
as

@leocreo

This comment has been minimized.

Copy link

@leocreo leocreo commented Oct 17, 2017

Thanks man!

@puneetthakur66

This comment has been minimized.

Copy link

@puneetthakur66 puneetthakur66 commented Oct 26, 2017

Thanks for this!

@lzwjava

This comment has been minimized.

Copy link

@lzwjava lzwjava commented Oct 31, 2017

Another way to fix it, use LumenServiceProvider instead:

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

This comment has been minimized.

Copy link

@bleuscyther bleuscyther commented Dec 4, 2017

Nice

@PeterKitonga

This comment has been minimized.

Copy link

@PeterKitonga PeterKitonga commented Apr 18, 2018

Thank you man!

@andre-bahia

This comment has been minimized.

Copy link

@andre-bahia andre-bahia commented May 21, 2018

Thank you man, it's works

@shift14wx

This comment has been minimized.

Copy link

@shift14wx shift14wx commented Aug 17, 2020

Thanks a lot!.

@gabriel-silveira

This comment has been minimized.

Copy link

@gabriel-silveira gabriel-silveira commented Sep 7, 2020

Another way to fix it, use LumenServiceProvider instead:

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

Thank you! This solved my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.