3

I have a small problem. I'm trying to make a Laravel package , but it won't load. Whenever I try adding it's provider in the config/app.php, I get:

Error class 'Something\HttpRequest\HttpRequestServiceProvider' not found

At the moment it has just the one file, situated in "vendor/something/http-request/src/HttpRequestServiceProvider". I'm suspecting something to do with the path, but I'm unsure.

I've tried

composer dump-autoload

but it doesn't get mapped.

Edit:

I've also published it to packagist and installing it via composer, in order to check that it works (well, it doesn't :D).

The service provider stub looks like this:

<?php

namespace Something\HttpRequest;

use Illuminate\Support\ServiceProvider;

class HttpRequestServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {

    }
}

So basically it's just the Laravel generated one. I doubt this is the source of the issue, but who knows.

Any ideas?

overburn
  • 1,194
  • 9
  • 27

1 Answers1

2

Doublecheck namespaces everywhere.

Don't forget to add your class to composer.jsom so Laravel could autoload it:

"autoload": {
    "classmap": [
        "database",
        "app/custom"
    ],
    "files": [
        "app/someFolder/customHelpers.php"
    ]

Run composer dumpauto after doing that. If it doesn't work, try to run composer dumpauto -o (with -o flag), sometimes it helps.

Update

When you upload your package to packagist and inistalling it with composer, you need to add autoload section to your package's composer.json, for example:

"autoload": {
    "psr-4": {
        "YourName\\YourPackage\\": "src/"
    }
}
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • Well, I've published the stub to packagist so I can try installing it directly with composer. I believe I shouldn't do anything other than add it to the require list and the service providers in the app config. Would it have anything to do with the fact that the service provider only has the boot and register methods and they are empty? – overburn May 04 '16 at 07:20
  • 1
    Actually, you need to add `autoload` section for it. Check updated answer. – Alexey Mezenin May 04 '16 at 07:24
  • 1
    Thanks a million, works like a charm. The more you know, heh. – overburn May 04 '16 at 07:33