Reputation: 1234
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?
Upvotes: 3
Views: 860
Reputation: 163758
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/"
}
}
Upvotes: 2