nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.38k stars 946 forks source link

Class Module ServiceProvider not found #283

Closed jakecorn closed 6 years ago

jakecorn commented 6 years ago

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.

nWidart commented 6 years ago

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.

jakecorn commented 6 years ago

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 } }

hybrid1969 commented 6 years ago

'composer update' should fix your issue.

nWidart commented 6 years ago

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

jakecorn commented 6 years ago

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

nWidart commented 6 years ago

Cool.

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

humphreymhonja commented 6 years ago

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 <?php

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"
bosz commented 5 years ago

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

DonOndeje commented 5 years ago

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

amirex128 commented 5 years ago

nice guys

kerell78us commented 3 years ago

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"

SocolaDaiCa commented 3 years ago
return [

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

    'namespace' => 'Modules',

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

kerell78us commented 3 years ago
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.

SocolaDaiCa commented 3 years ago
{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "Modules/",
      "KerwinEllis\\": "Modules/"
    }
  }
}

you need config autoload

SocolaDaiCa commented 3 years ago

after that, maybe need run composer dumpautoload

kerell78us commented 3 years ago

, "KerwinEllis\": "Modules/"

Aha, it worked, @SocolaDaiCa thanks a million

mubi351 commented 2 years ago

Thank you.It worked for me also

Vatiraije commented 4 months ago

Hi, i have problem when testing my laravel api in postman i am getting this error" Error: Class "App\Models\ServiceProvider" not found in file C:\xampp\htdocs\GMS\adminS-laravel\app\Http\Controllers\Api\FormSubmissionController.php on line 22" however i have configured everything that needs to be configured .please help me fix this error

mardhy21 commented 3 months ago

how to fix it Class "Modules\Products\Providers\ProductsServiceProvider" not found in laravel 11

dcblogdev commented 3 months ago

how to fix it Class "Modules\Products\Providers\ProductsServiceProvider" not found in laravel 11

ensure you've updated composer:

from v11.0 autoloading "Modules\": "modules/", is no longer required.

By default, the module classes are not loaded automatically. You can autoload your modules by adding merge-plugin to the extra section:

"extra": {
    "laravel": {
        "dont-discover": []
    },
    "merge-plugin": {
        "include": [
            "Modules/*/composer.json"
        ]
    }
},

Tip: don't forget to run composer dump-autoload afterwards

GempitaRizki commented 3 months ago

how to fix it Class "Modules\Products\Providers\ProductsServiceProvider" not found in laravel 11

same issue on laravel 11

GempitaRizki commented 3 months ago

"merge-plugin": { "include": [ "Modules/*/composer.json" ] }

its work , Thank you

jhonymiler commented 3 months ago

Run the command: artisan module:publish Add the "namespace" variable to the items in the "generator" array. image

The team forgot about PSR-4 with PHP 8.2.

mardhy21 commented 3 months ago

Done, tnks

On Thu, Mar 28, 2024, 12:22 PM Jonatas Miler Oliveira < @.***> wrote:

Run the command: artisan module:publish Add the "namespace" variable to the items in the "generator" array. image.png (view on web) https://github.com/nWidart/laravel-modules/assets/18699320/77055a84-2507-4e01-8613-87670d25a8fc

The team forgot about PSR-4 with PHP 8.2.

— Reply to this email directly, view it on GitHub https://github.com/nWidart/laravel-modules/issues/283#issuecomment-2024368539, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATCCOZAWISR4QTWZHURY2OTY2OLG5AVCNFSM4DUFBMEKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBSGQZTMOBVGM4Q . You are receiving this because you commented.Message ID: @.***>

mnarbash commented 2 months ago

In Laravel 11 and Laravel Module 11, ensure that "wikimedia/composer-merge-plugin" is set to true in composer.json, like this:

    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true,
            "wikimedia/composer-merge-plugin": true
        }
    },