Laravel-modules: Help needed in installing module specific composer dependency

Created on 29 Jan 2017  路  7Comments  路  Source: nWidart/laravel-modules

I am creating a chat module using https://github.com/nahid/talk. But I am not able to setup dependency properly and getting some errors.

I have followed steps in order to add dependency https://github.com/nahid/talk.

  1. Create Chat Module
php artisan module:make Chat
  1. under app/Modules/Chat I have applied following commands
composer require nahid/talk
  1. Added Providers in module.json as follows
{
    "name": "Chat",
    "alias": "chat",
    "description": "",
    "keywords": [],
    "active": 1,
    "order": 0,
    "providers": [
        "App\\Modules\\Chat\\Providers\\ChatServiceProvider",
        "Nahid\\Talk\\TalkServiceProvider"
    ],
    "aliases": {
        "Talk": "Nahid\\Talk\\Facades\\Talk"
    },
    "files": [
        "start.php"
    ],
    "requires": [

    ]
}
  1. Fired on command line composer dump-autoload

After following above steps I am getting following error.

FatalThrowableError in Application.php line 610:
Class 'Nahid\Talk\TalkServiceProvider' not found

----
in Application.php line 610
at Application->resolveProviderClass('Nahid\Talk\TalkServiceProvider') in Application.php line 561
at Application->register('Nahid\Talk\TalkServiceProvider') in Module.php line 260
at Module->registerProviders() in Module.php line 226
at Module->register() in Repository.php line 296
at Repository->register() in BootstrapServiceProvider.php line 22

Notes:
I have already enabled scanning in config/modules.php
I have checked that without this dependency module is working fine.

Am I missing anything here?

Any help would be great.

Most helpful comment

Hello,

Sorry for the late reply.

You ran the require command inside the module's folder, meaning it added a vendor folder in there.

It's a good idea to add the module's dependencies on its composer.json file, however afterwards this needs to be added on the main composer.json file.

This can be done automatically using php artisan module update chat.

I hope this clears up the issue you're encountering.

All 7 comments

Running the composer command with -o should fix this

I have run following composer command but its not working.

composer -o dump-autoload

I have run command in Module directory & project directory but did not work.

Hello,

Sorry for the late reply.

You ran the require command inside the module's folder, meaning it added a vendor folder in there.

It's a good idea to add the module's dependencies on its composer.json file, however afterwards this needs to be added on the main composer.json file.

This can be done automatically using php artisan module update chat.

I hope this clears up the issue you're encountering.

Hi everyone. It's posible to have few composer.json inside modules to install requires but not change the root composer file with module:update command?

Would be nice, if the root (project) composer.json files doesn't needs to be updated. Totally agree to @enextiarg
Is there a possibility to do so?

I mean, for me a module should be independent form anything else. It should work standalone. Otherwise you need to execute a bunch of commands when adding a module even on a live system for example.

Ce serait bien si les fichiers root (project) composer.json n'ont pas besoin d'锚tre mis 脿 jour. Enti猫rement d'accord avec @enextiarg
Y a-t-il une possibilit茅 de le faire?

Je veux dire, pour moi, un module doit 锚tre ind茅pendant de toute autre chose. Cela devrait fonctionner de mani猫re autonome. Sinon, vous devez ex茅cuter un tas de commandes lors de l'ajout d'un module, m锚me sur un syst猫me en direct par exemple.

indeed I'm of the same opinion as you, I don't know if it has been fixed but if not I would create a command that will read all the composer files of each module and then rewrite the root composer file.

You can look up the composer merge plugin which helps with this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

n4p4 picture n4p4  路  17Comments

cristiangervasi picture cristiangervasi  路  12Comments

kamov picture kamov  路  10Comments

elephantux picture elephantux  路  11Comments

ridwanskaterock picture ridwanskaterock  路  12Comments