11 months ago

Share classes between projects with composer does not work.

Posted 11 months ago by ImArtur

I'm creating a project. It will be pretty big admin application and client application. Both of those applications need to run separately. Those projects will share the same database and many modals, enumerations, transformers will be shared between each other. Structure is as follow:


I was thinking about creating packages folder to hold all my models so I can require it into each project. This is how I did it:

packages composer.json:

  "name": "system/db",
  "description": "db",
  "type": "library",
  "autoload": {
    "psr-4": {
      "System\Db\": "src"

I created Test class in packages:

namespace System\Db;
class Test
    public function hai(){
        echo 'Hi';

After that I required it into my 'admin' project like this:

        "system/db": "*"

I run:

composer dump-autoload

and Tried to test it:

use System\Db\Test;

Route::get('/', function () {
    (new Test())->hai();
    return view('welcome');

I get a error:

"Class 'System\Db\Test' not found"

Any ideas why? Do you have better idea to share data between projects? Thanks

Please sign in or create an account to participate in this conversation.