As my given promise into my previous discussion into point 3: “We will discuss in next blog on How to deploy our package at packagist.org”, Let’s we learn on how to submit our Laravel first package.
I think you have now your first package with you which looking for submitting over the live/public server which is packagist.org.
- Laravel package
- GitHub repository with public branch
Here you need to check first that created package is working fine. After that, we need to test our package.
NOTE: Make note here that we must pick a package unique name to avoid conflicts in the future and this is a very important step because package name is not changeable once it posted to packagist.org
Here, we need to make some simple test of our create a package of locally. So for that, first add "PHP >=5.3.0" inside "composer.json", Composer will install only its own files. With this composer will install require file and create folder vendor with autoloading files.
Now install the composer using: composer install
We need to update composer.json as per given instruction into packagist.org. Once installed it will generate vendor folder at your package root folder composer and autoload.php which will use to make basic testing for the package.
Create tests folder inside package root directory with tests/test.php. This file contains the code for the basic testing code of your created package. tests/test.php code look like:
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Addweb\Sample\SampleController; //Perform your testing .... Go to the terminal or create a PHP web server inside "tests" dir and run command: php tests/test.php
TIP: You can get some help from Laravel Testing Helper for Packages Development. Must read it.
Package send to packagist.org
Now our package is working fine and we need to send this package to packagist.org. And for that, we first need to upload our package to GitHub public repository. Go to GitHub Repo help Once it repository ready, add the package to the public branch and store that branch URL. Now our package is ready to send at packagist.org.
Login to your packagist account or create new here. If you have already account open the submit package page by clicking here. At this page, packagist.org ask you “Repository URL (Git/Svn/Hg)”, a place that GitHub repository URL here and click on “Check” button to check and submit the package.
If the package is correct then packagist.org will return package name and it’s done.
TIP: If you update your package and commit code into GitHub then you also need to update the packagist.org for taking this changes into your live package this process called ‘Force Update’ you can also set up ‘Auto Update’ using GitHub Service Hooks. For Auto Update, Add ‘Packagist’ service hook into your GitHub > Settings > Service Hooks > Add Packagist as service hook.
Hope this blog helped you to explore and built your package. Need more assistance regarding Laravel Web Development Services Contact Us now!