Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CharlesW's avatar

Fixing apparent Laravel package incompatibility with Lumen

Hello,

I'm getting Call to undefined function errors in Lumen with two different Laravel Plupload service providers, I think because of this (similar) code:

    /**
     * Perform post-registration booting of services.
     */
    public function boot()
    {
        $this->publishes([
            __DIR__.'/../../../public/assets' => public_path('vendor/jildertmiedema/laravel-plupload/'),
        ], 'public');
    }

Here's the full error I get when I use php artisan vendor:publish:

Fatal error: Call to undefined function JildertMiedema\LaravelPlupload\public_path() in /Users/Charles/Projects/XXX/YYY/ZZZ/vendor/jildertmiedema/laravel-plupload/src/JildertMiedema/LaravelPlupload/LaravelPluploadServiceProvider.php on line 32

Call Stack:
    0.0024     226160   1. {main}() /Users/Charles/Projects/XXX/YYY/ZZZ/artisan:0
    0.0034     234600   2. require('/Users/Charles/Projects/XXX/YYY/ZZZ/bootstrap/app.php') /Users/Charles/Projects/XXX/YYY/ZZZ/artisan:18
    0.0500    2819232   3. Laravel\Lumen\Application->register() /Users/Charles/Projects/XXX/YYY/ZZZ/bootstrap/app.php:84
    0.0509    2833696   4. JildertMiedema\LaravelPlupload\LaravelPluploadServiceProvider->boot() /Users/Charles/Projects/XXX/YYY/ZZZ/vendor/laravel/lumen-framework/src/Application.php:258
                                                                           
  [Symfony\Component\Debug\Exception\FatalErrorException]                  
  Call to undefined function JildertMiedema\LaravelPlupload\public_path()  

I'm a Laravel/Lumen newbie, so although I think I understand what's going on here (assets needed by the service are being copied to a public assets folder), I don't understand why it's failing. Any help is appreciated!

— Charles

0 likes
16 replies
jimmck's avatar
jimmck
Best Answer
Level 13

@CharlesW I got it to publish. I added the public_path function to lumen helpers file.

if (!function_exists('public_path')) {
    /**
     * Return the path to public dir
     *
     * @param null $path
     *
     * @return string
     */
    function public_path($path = null)
    {
        return rtrim(app()->basePath('public/' . $path), '/');
    }
}

Found info on that here:

https://gist.github.com/vluzrmos/30defc977877e0eba7b2

Did you configure your Lumen install to publish and create a config directory?

http://laravelista.com/json-web-token-authentication-for-lumen/

Now do we have an example to test?

My app.php

$app->register('Tymon\JWTAuth\Providers\JWTAuthServiceProvider');
$app->register('Aws\Laravel\AwsServiceProvider');
$app->register(Appzcoder\LumenRoutesList\RoutesCommandServiceProvider::class);
$app->register(JildertMiedema\LaravelPlupload\LaravelPluploadServiceProvider::class);

//$app->register('Barryvdh\Debugbar\ServiceProvider');

/** This gives you finer control over the payloads you create if you require it.
 *  Source: https://github.com/tymondesigns/jwt-auth/wiki/Installation
 */
class_alias('Tymon\JWTAuth\Facades\JWTAuth', 'JWTAuth');
class_alias('Tymon\JWTAuth\Facades\JWTFactory', 'JWTFactory'); // Optional

class_alias('Aws\Laravel\AwsFacade', 'AWS');
class_alias('Collective\Html\HtmlFacade', 'HTML');
class_alias('Collective\Html\FormFacade', 'Form');
class_alias(JildertMiedema\LaravelPlupload\Facades\Plupload::class, 'Plupload');

3 likes
jimmck's avatar
Jamess-MacBook-Pro:lumen jimm$
Jamess-MacBook-Pro:lumen jimm$ php artisan vendor:publish
Copied Directory [/vendor/jildertmiedema/laravel-plupload/public/assets] To [/public/vendor/jildertmiedema/laravel-plupload]
Publishing Complete!
Jamess-MacBook-Pro:lumen jimm$

willvincent's avatar

Lumen does not provide all of the functionality that's available in laravel. So the expectations it has for service providers are different.. if you want to use this in lumen, you'll probably have to fork and make a bunch of changes... or you could use laravel instead of lumen.

It doesn't seem to me you'd really want that kind of a package with lumen though to begin with.. lumen is really intended for building a very light-weight api, not something that's also going to be providing a full frontend/etc.. you might be better off using laravel.

Or, include plupload in your frontend app, since it is just a javascript library, and point it to the appropriate api routes that you manually build out with lumen.

1 like
CharlesW's avatar

Lovely! Adding compat_l5.php and VendorPublishCommand did the trick. Thank you!

As a Larvel/Lumen newbie, I don't quite get what's going on here big-picture-wise. Should I not expect to be able to use Laravel service providers as-is with Lumen? Is it intentional that for places where Lumen shares docs with Laravel, there can be caveats that aren't spelled out? Or do we think these are just growing pains because Lumen is shiny and new?

Mostly, just wondering if it was a poor choice to use Lumen instead of Laravel for my API.

— Charles

jimmck's avatar

@CharlesW Lumen is just lightweight Laravel. There is no magical difference. Turn on what you need. As you saw when you added the helpers. I don't use Eloquent, I have my own model library. Lumen speeds up the whole interface. Now I added a route, I need a Browser piece to test front end. The examples I found are depending on Flash or Silverlight???

1 like
CharlesW's avatar

@willvincent: Or, include plupload in your frontend app, since it is just a javascript library, and point it to the appropriate api routes that you manually build out with lumen.

Makes sense, and that's how I'm currently building — Larvel for the front-end, Lumen for the API.

@jimmck: Lumen is just lightweight Laravel. There is no magical difference.

Yeah, I thought Lumen would just be Laravel with stuff turned off by default. But important stuff is missing and it seems like devs are expected to know how to port additional Laravel stuff over if needed. I expect that seems pretty straightforward to you, but I'm not quite there yet. :O) Thanks again!

— Charles

willvincent's avatar

I guess I don't understand if you're using laravel to provide your frontend why you wouldn't also build the backend into it too.. to my mind lumen makes the most sense when you just need a simple api to back something like a javascript frontend, or the like..

CharlesW's avatar

@willvincent: I guess I don't understand if you're using laravel to provide your frontend why you wouldn't also build the backend into it too.

Lumen is intended for microservices and APIs, and the REST API I'm building falls squarely into that territory, so it seemed to make sense. Effectively, I bought the messaging on the home page at face value. :O)

I'd appreciate any thoughts from experienced Laravel users on why that might not be the best way to go.

— Charles

willvincent's avatar

Right, sure.. but why a separate (server side) app that talks to it? /shrug/ everybody's got their own needs I guess :)

At any rate -- you shouldn't need the plupload package in your rest api, since plupload is client-side JS... a laravel package for a client-side library seems largely unnecessary.

CharlesW's avatar

@willvincent: why a separate (server side) app that talks to it?

The service will support a PC/mobile website, but also a mobile app and devices as well. It's mostly a matter of wanting to be able to scale and control access to the front-end and the service separately.

you shouldn't need the plupload package in your rest api

Part of the package is client-side support (which I'll be using as well), but I also need it to support chunked transfer encoding for large file uploads.

— Charles

jimmck's avatar

Guys. As a dev who has worked with many languages, API's, databases and more frameworks (Than Dead Cats :) Its seems that this Laravel world of devs is under the impression it just makes things work. It does not. Lumen is a manual transmission version of Laravel. Laravel is still a very young codebase. There are parts that need to mature. Windows 1.0 was very flawed. The docs did not always match your code. You had to figure out what was going on. @CharlesW I appreciated your question, I will use it as a take away to finish the investigation. Learn how things work and form your own opinion. Choosing Laravel or Lumen or whatever, you are going to face issues. @willvincent Client side libraries have been talking to server side libraries since you could cross wire a serial port. Or write a VT100 display module library in DIBOL and call RSTS/E libraries to DEC ISAM libraries. Enjoy the coding :) :)!!! One reason I like Jeff, he always advocates, Read The Code!!!!

jimmck's avatar

BTW. I am so bummed that Halt and Catch Fire ended last week. So Bummed!!!!

willvincent's avatar

Client side libraries have been talking to server side libraries since you could cross wire a serial port.

Yeah. obviously. What's your point? o.O

ShivarajRH's avatar

I added directory seperator for cross operating system support:

if ( !function_exists('public_path')) { function public_path($path = null) { return rtrim( app()->basePath( DIRECTORY_SEPARATOR.'public'. ($path ? DIRECTOY_SEPARATOR . $path : $path) ), '/'); } }

Please or to participate in this conversation.