Package:discovery Does Not Find My ServiceProvider
I have created a custom Laravel package. Its hosted on a private repository.
When I try to install the package in a Laravel application like this:
composer require memberportal/congress-models
I get this error:
In ProviderRepository.php line 208:
Class 'Memberportal\CongressesModels\CMServiceProvider' not found
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
I have double checked everything a hundred times, but I am clueless why he doesn't find the class CMServiceProvider.php
.
Do I need to specify the provider anywhere else then in the composer.json
?
This is the content of composer.json
from my package:
{
"name": "memberportal/congress-models",
"description": "Takes care of the models between API and client",
"type": "metapackage",
"authors": [
{
"name": "My name",
"email": "[email protected]"
}
],
"version" : "1.0",
"minimum-stability": "stable",
"require": {
"laracasts/presenter": "^0.2.2"
},
"require-dev": {
"orchestra/testbench": "^4.0"
},
"autoload": {
"psr-4": {
"Memberportal\\CongressesModels\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Memberportal\\CongressesModels\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"Memberportal\\CongressesModels\\CMServiceProvider"
]
}
}
}
This is the folder structure:
This is the content of CMServiceProvider.php
:
<?php
namespace Memberportal\CongressesModels;
use Illuminate\Support\ServiceProvider;
class CMServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
}
}
Answer
Since you want to install a Laravel package your package type should be package
. A metapackage
is a package that does not contain actual software, it simply depends on other packages to be installed.
In short, change
"type": "metapackage",
to
"type": "package",
and Laravel will find the service provider with auto-discovery when the package is required by composer.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?