Use Custom Git Repository on your Laravel Project
When working on Laravel projects, you may come across a package that fits your needs but requires some modifications. Instead of waiting for the maintainers to merge your changes, you can fork the package and install your customized version. In this guide, we'll go through the steps to install a forked package in your Laravel project.
Before we dive into the guide though, here's how I got here.
So I finally decided to upgrade my blog to Laravel 11. It's typically a straight forward process, I just needed to follow the steps on the official docs. But in this case, I'm using the Laravel Torchlight Client by Aaron Francis which hasn't been receiving updates recently.
Torchlight is a VS Code-compatible syntax highlighter that requires no JavaScript, supports every language, every VS Code theme, line highlighting, git diffing, and more.
The last update was on February 27, 2024. Where the maintainer bumped the dependencies for Laravel 11; which's good enough for what I want to do. But since I'm using the CommonMark parser, I also make use of the Laravel Torchlight Extension for Commonmark (also made by Aaron) and this where things got a bit complicated.
This extension hasn't been updated to be compatible with Laravel 11 yet, so I decided to check its status on GitHub and I realized that there is a pending Pull Request, since May 16, 2024, asking to do exactly what I wanted to do.
Now that you know the why, let's get to the how. I'm going to use the case of the Laravel Torchlight Extension for Commonmark.
1. Before you install a modified version of a package you need to fork it:
- I went to the repository of the package on GitHub.
- Clicked the Fork button to create my own copy under my GitHub account.
- Cloned the fork to my local machine:
git clone https://github.com/Khal-ID/torchlight-commonmark-php.git
- Then I made my modifications, committed, and pushed them to my forked repository.
The changes I made were just to bump the versions in composer.json, so nothing too complicated.
} ], "require": {- "php": "^7.2|^8.0", - "torchlight/torchlight-laravel": "^0.5.10", + "php": "^7.2|^8.0|^8.2", + "torchlight/torchlight-laravel": "^0.5.10|^0.6", "league/commonmark": "^1.5|^2.0" }, "require-dev": {
2. Install the forked package
Before installing my forked package I went ahead and removed the outdated version from my project:
composer remove torchlight/torchlight-commonmark
Then I opened composer.json on my Laravel project and added the following lines:
"repositories": [ { "type": "vcs", "url": "https://github.com/Khal-ID/torchlight-commonmark-php" } ], "require": { "torchlight/torchlight-commonmark": "dev-main" }
Note that "dev-main" refers to the branch you want to use (e.g., "dev-master", "dev-feature-branch").
After that I just ran composer update
on my Laravel project and voila.
To verify the package installation you can run the following console command inside of your project:
composer show torchlight/torchlight-commonmark
This will display details about the installed package, including its source.
You can always keep an eye on the original repository so when it gets the updates you need, you can swap to it. And if you believe that the changes you made could benefit other developers don't hesitate to submit a pull request. In my case, there's already a similar pull request pending, so there's no need to submit another one.
Torchlight for Laravel is a wonderful package (just look at how beautiful the highlighted pieces of code are 😃) and I hope Aaron could get sometime to update it and keep it alive.
Hope this was helpful, until next time. ✌️