Laravel-modules: Class Module ServiceProvider not found

Created on 24 Jul 2017  路  16Comments  路  Source: nWidart/laravel-modules

hi,

I would like to ask about this problem.

I able to create a module named Teacher using this command php artisan module:make Teacher. However, when I create another module or even run php artisan serve it shows me this error.

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Modules\Teacher\Providers\TeacherServiceProvider' not found

Every command I tried but it shows me the same error I even tried php artisan.

I already added this 'Module' => Nwidart\Modules\Facades\Module::class, to aliases and Nwidart\Modules\LaravelModulesServiceProvider::class, to provider.

please help me , thank you.

Most helpful comment

Hello,

That means your module was created, the package found your service provider, but composer wasn't able to load the service provider.

Meaning you probably forgot to add the psr-4 part of the documentation.

All 16 comments

Hello,

That means your module was created, the package found your service provider, but composer wasn't able to load the service provider.

Meaning you probably forgot to add the psr-4 part of the documentation.

Thank you for the response.

Im done with psr-4 but the error is still there.
This is my code in composer.json

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.",
"laravel/tinker": "~1.0",
"nwidart/laravel-modules": "^1.27"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.
",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\": "app/",
"Modules\": "Modules/"
}

},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}

'composer update' should fix your issue.

or dump autoload (which is run after an update).

I found same issue https://github.com/nWidart/laravel-modules/issues/4, same solution as you have just suggested,this fixed my problem. Thank you

Cool.

I've added this info on the readme and documentation website. 馃憤

hi,
i have this problem in my app laravel5.4 itried to display the output but i get an error of app\Instructor not found still i define it at the top

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use app\Instructor;

class CreatesController extends Controller
{
   public function home(){
       $instructors=Instructor::all();
       print_r($instructors);

          }
   }

Arguments

"Class 'app\Instructor' not found"

Oh, i had this same issue, as @nWidart pointed out, I forgot to add "Modules\\": "Modules/" to my composer.json. As soon as i added it and did composer dump-autoload, it works.

Thanks for the awesome package @nWidart

Great...I had the same issue but it is all fixed now. Thanks @nWidart

nice guys

Hey Guys, I have a question regarding the usage of namespace (with the laravel-module package). Is that we're tied to using the namespace "Modules" instead of the Developer's name as per below;
"Modules\Activity\Providers\ActivityServiceProvider" instead of "DeveloperName\Activity\Providers\ActivityServiceProvider"

return [

    /*
    |--------------------------------------------------------------------------
    | Module Namespace
    |--------------------------------------------------------------------------
    |
    | Default module namespace.
    |
    */

    'namespace' => 'Modules',

You can config namespace before create new module, It is DeveloperName

return [

    /*
    |--------------------------------------------------------------------------
    | Module Namespace
    |--------------------------------------------------------------------------
    |
    | Default module namespace.
    |
    */

    'namespace' => 'Modules',

You can config namespace before create new module, It is DeveloperName

Thanks @SocolaDaiCa. That's what I thought but when I change it I get Class "KerwinEllis\Listing\Providers\ListingServiceProvider" not found.

{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "Modules/",
      "KerwinEllis\\": "Modules/"
    }
  }
}

you need config autoload

after that, maybe need run composer dumpautoload

,
"KerwinEllis\": "Modules/"

Aha, it worked, @SocolaDaiCa thanks a million

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bhattraideb picture bhattraideb  路  12Comments

Alercard picture Alercard  路  29Comments

oleaass picture oleaass  路  11Comments

esipavicius picture esipavicius  路  13Comments

echemik picture echemik  路  10Comments