I am trying to learn Laravel Package Development. I have a minimalistic package containing one route, migration, seeder and config.
On my package, I have inserted the following in my composer.json
"extra": {
"laravel": {
"providers": [
"Test\TestServiceProvider"
]
}
},
I am then trying to install this package on another new local Laravel project. So in my new Laravel project, I have added the following to my composer.json
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": {
"local": {
"type": "path",
"url": "../test",
"options": {
"symlink": true
}
}
}
I then require the test package with composer require test/test
This all seems to work. In my console I can run my migrations, seed my database and publish my config files etc. I thought life was all good.
But then I tried to view my Laravel package in a browser. I get the following error message
Error Exception
include(/home/vagrant/code/test-app/vendor/composer/../test/test/src/TestServiceProvider.php): Failed to open stream: No such file or directory
Do I need to manually publish my Service Provider as well? What about other files I intend to build, like models, controllers etc?
What am I missing to get this to work in a browser? Ironically, the Laravel app worked before I imported my package
So I found the answer. Bit stupid of me really, but in case anyone else makes the same mistake, I thought I should share.
My package is added to my test project via a symlink (dictated in the project’s composer.json file). But I am using Homestead for my server (forgot to mention that), and in my homestead.yaml file, I had created folders for my test project, but not for my package. So when the site is being delivered through Homestead, the relative path to my package didn’t exist on the server. Updating my homestead.yaml file to include a folder for my package did the trick.