How to Submit a Non-trivial PR to a Laravel Package

Posted in Tutorials by Cristian Tabacitu - 25th of January 2020

If you want to contribute to a Laravel package with a PR, sometimes the Github interface is enough. You change one or two files there and submit your small PR. But more often than not, when your PR is more than a quick fix, you'll need to do this right. You'll need to test your work, before you submit the PR. To do that, you'll want to install the package on your computer, make the changes, test your work, and only then submit the changes as a PR.

This is how I do it. The process below works even if you can't normally install the package in your project with Composer, because of dependency conflicts.

Let's say you'd like to make profound changes to UserManager to provide support for Backpack v4, when previously it only supported Backpack v3.

  1. Fork the repo using Github's button.

  2. Clone your fork inside a Laravel installation:

git clone [email protected]:tabacitu/UserManager.git packages/usermanager
# notice we've cloned the package inside packages/packagename
  1. Add the service provider to your config/app.php file:
        EduardoArandaH\UserManager\UserManagerServiceProvider::class,
  1. Add the local requirement to your composer.json file:
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
-            "App\\": "app/"
+            "App\\": "app/",
+            "EduardoArandaH\\UserManager\\": "packages/usermanager/src"
        }
    },
  1. Run composer dump-autoload

This will make your Laravel installation run the package from your computer, using a git repo that is linked to your fork. When you're done making changes you can:

cd packages/usermanager
git commit -am "changes"
git push origin master
# this will have pushed your changes online, on your fork
# now you can go to your fork on Github, and use interface to start a new Pull Request to the original repo 

This could look more complicated than necessary, at first glance. I know. It's always been a chore. But it's the fastest way I know how to do this, without using any third-party package or library.

Hope it helps someone, someday.