How to fork and maintain laravel package with ease

There are a lot of amazing ready to use laravel packages on Github and packages. Every project uses open-source packages. The only problem with open source is the lack of maintenance as it is not a full time paid job for contributors.

Laravel is a very rapidly developed PHP framework with a new major release every six months. It is an additional overhead for package maintainers. You may end up with a situation when the package is not updated to be compatible with the latest framework version. In this case, you have to create your fork. I’m going to share my way of creating and maintaining forks.

For example, you have this package in your composer require section:

"require": {
"tokenly/laravel-vault": "^0.2.3",
}

You may see that package is not supported, and the last release was a few years ago. Also, I suggest checking the existing forks. Maybe someone already did your job:)

If no, then you have to create your fork. Just click on Forks button and follow instructions. Now you will see the same code but under your username or organization

The next step is to clone code into your project. I prefer cloning into the packages directory

git clone git@github.com:tenantcloud/laravel-vault.git packages/Tenantcloud/LaravelVault

To be able to work with the source code, you have to make a few adjustments:
Edit your main composer.json. It will make composer pulling tenantcloud/laravel-vault package from the local folder via a symlink

"repositories": [
{
"type": "path",
"url": "packages/TenantCloud/LaravelVault"
}
],
"require": {
"tenantcloud/laravel-vault": "*",
},

Also, edit your package composer.json with a proper name instead of original tokenly/laravel-vault

{
"name": "tenantcloud/laravel-vault"
}

Run composer update command, and you will see a symlink in your vendors/tenantcloud folder.

Now you can edit code, test it in your real project and push it to GitHub.

Next step is to publish a new release on GitHub

Then you can publish it on a packagist (you can read instructions here https://medium.com/@ivankolodiy/laravel-7-package-development-from-scratch-7887678ae38 Step 3)

After that, you have to edit your main composer.json. Remove this

"repositories": [
{
"type": "path",
"url": "packages/TenantCloud/LaravelVault"
}
],

And update require block with your published version

"require": {
"tenantcloud/laravel-vault": "^0.2.4",
},

Run composer update again, and the symlink will be removed with the code from Github.

Finally, you can ignore your packages directory or remove it if you don’t need that for now.

Enjoy your forking and contribute to open source!

CTO at TenantCloud