Test your Laravel packageš¦ locally in your Laravel project
Recently, while we were developing a new Laravel package, we wanted to check and ensure that everything works as expected in an āactualā Laravel project.
While developing the package, we need a quick way to check functionality.
To do so, follow below steps:
1) Add your package in Laravel project: Letās name it āmypackageā, add it to root directory of your project.
2) Add package ārepositoriesā block in your composer.json. For general information on how to declare repositories, please refer to the composer documentation.
composer.json
{
...."repositories": {
"dev-package": {
"type": "path",
"url": "mypackage", // Path to your package folder
"options": {
"symlink": true
}
}
}....}
By setting the "type": "path"
composer knows that you would like to reference a local repository and the url
defines the package location.
symlink
option and composer will create a symlink to the package folder in vendor
directory.
3) The last step is to issue a composer require
command to include the package in your Laravel project.
composer require radicalloop/mypackage @dev
After executing this command the package folder is symlinked into the applicationās vendor folder
and every change to your package will be immediately available in your application.
Thatās it! Now you should be able to use/test your package in your Laravel project. Big thanks to composer. š
Any questions or suggestions? please comment!