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

rw_lara's avatar

@bobbybouwmann @mstnorris

Ok so I managed to sort of get it working.

I had to put the following in my root composer.json file:

        "psr-4": {
            "App\\": "app/",
            "Bobbybouwmann\\Entry\\": "packages/bobbybouwmann/entry/src/Entry"

        }

And then in my command line I ran the following:

composer dump-autoload -o

And it worked.

However as soon as I do composer dump-autoload without using -o.

So:

composer dump-autoload

Then it breaks again.

Why would optimizing the composer dump-autoload make it work over not optimizing it?

rw_lara's avatar

@ bobbybouwmann

doing just a composer dump-autoload comes up with service provider not found error. but using -o at the end makes it all work.

bobbybouwmann's avatar

That's odd... Well it fixed for now at least! If I find anything related to this I will let you know ;)

jotafurtado's avatar

I have same problem...

using composer dumpautoload -o works

but after execute any command php artisan make:somenthing

My custom package service provider is marked as NOT FOUND

cristian9509's avatar

@timless Did you manage to figure out what was wrong? I struggled a couple of hours and finally realized what was happening. Had the exact same issue as you.

First of all, when you create a package locally you will need to have it autoloaded (psr-0 or psr-4) form the root composer.json. I figured out the if you did not install the package through composer, than it will not be autoloaded by `composer dump-autoload' (if you don't add it to the root composer.json).

The second problem, and this happened in my case as well, was that I placed the package on Packagist and was installing it through composer, but the issue was that I had the wrong psr-4 path and my service provide was never found.

vermond125's avatar

@cristian9509 I had the same problem, but found a solution, anyway it worked for me (tested on laravel 5.2.* on windows 10).

  • Let me use this directories structure:
{YourLaravelApp}
--packages
----vendor
------package
--------src
----------PackageServiceProvider.php
--------composer.json
  • You ServiceProvider class must exist.
namespace Vendor\Package;

use Illuminate\Support\ServiceProvider;

class PackageServiceProvider extends ServiceProvider { ... }
  • composer.json file in your package have to contain autoload rule.
{
    ...
    "autoload": {
            "psr-4": {
                    "Vendor\\Package\\": "src/"
            }
        },
    ...
}
  • You have to register your PackageServiceProvider in config/app.php config file.
'providers' => [
    ...
    Vendor\Package\PackageServiceProvider::class,
    ...
];
  • And, you know, just to be sure... To your main composer.json file add this autoload rule.
{
    ...
    "autoload": {
        ...
            "psr-4": {
            ...
                    "Vendor\\Package\\": "packages/vendor/package/src/"
            }
        },
    ...
}
  • After all that stuff in your console:
composer dump-autoload -o
php artisan vendor:publish

Hope, this helps.

4 likes
chrisgibson's avatar

I had this exact same problem, and I can confirm that the bullet point "composer.json file in your package have to contain autoload rule", in the post above, was the key for me. It seems that the composer.json file for your package needs to contain the correct autoload rule; this isn't made clear in the jaiwalker tutorial . Thanks @vermond125.

dileepthomas's avatar

I am just new to this laravel, there are two composer.json files, one is inside the package and another one outside. As you have been already posted the composer.json file (inside the package). can you just verify the name under psr-4 on outside composer.json file

lamallam's avatar

give permission to www-data to access your laravel-log file

Kaheriger's avatar

Mist of the times you have to face the issues while providing the services to others. Although, it seems that college-paper.org reviews are sharing more common examples that are there to facilitate users on daily basis.

Previous

Please or to participate in this conversation.