Laravel-medialibrary: FatalThrowableError: Call to undefined function Spatie\MediaLibrary\config_path()

Created on 4 Jul 2017  路  4Comments  路  Source: spatie/laravel-medialibrary

I'm using Lumen and receive the following after installation:

(1/1) FatalThrowableError Call to undefined function Spatie\MediaLibrary\config_path() in MediaLibraryServiceProvider.php (line 20) ...

This function isn't available in Lumen. Would there be any way to either

  • Solve the problem without it
  • Try to determine whether there's a .env file somewhere and use that instead
  • Provide a fallback config_path function

... so we don't have to edit library files? That'd be gorgous 馃榿

EDIT: Maybe something like defining a helpers.php like laravel, adding it to the autoloader config under files:

if (! function_exists('config_path')) { /** * Get the path to the configuration files. * * @return string */ function config_path() { return app()->basePath().'/config'; } }

Most helpful comment

@Shadomax I ultimately settled with a custom solution more specific to my project, however I solved this specific issue with my own helpers.php file (using the function I proposed above) and included that in composer's autoload section, like so:

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

That way, your helpers file will be autoloaded right away, including the function and making the library work fine.

All 4 comments

I'm not a Lumen user, so I'm probably not going to make any changes to support Lumen. It's best that you make the necessary changes in your own project. Writing your own service providers or manually write the missing functions would be a good solution. Our maybe you could just upgrade your project from Lumen to Laravel.

While I think your point is valid, I'd like to express my disagreement considering this small change is the only one necessary to make Lumen work projects out of the box, without modifying files below vendor/, and you already give usage instructions for Lumen projects.
Proposing people to switch frameworks isn't a real recommendation either, they probably had a reason for their decision.

Thank you for your prompt response, though.

how did you solve this error @Radiergummi ?

@Shadomax I ultimately settled with a custom solution more specific to my project, however I solved this specific issue with my own helpers.php file (using the function I proposed above) and included that in composer's autoload section, like so:

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

That way, your helpers file will be autoloaded right away, including the function and making the library work fine.

Was this page helpful?
0 / 5 - 0 ratings