Creating custom packages - Laravel 5.x
Custom packages is a simple practical example showing a way to build customized packages in Laravel. In this example you are going to go through every step of developing your own custom packages.
Folder structure
The first thing we need to do is set up our folder and name-spacing structure of our package, this is very important and it follows a standard know as PSR-4. Most packages that have this structure use the following path name:
vendor/package-name
where "package name" is your package name, such as, "simple-admin" and vendor would be the package folder name. However, you will be able to find the example package in the application root folder, which is a folder named "packages"
packages/simple-admin
Using Composer
Now that we have our folder structure the first thing we need to do is create a composer.json file for our package. This is required so that we can make our package available to download to the public as well as define any dependencies the package requires.
In order to do that you need to go inside the “simple-admin” directory and run the following command
composer init
After following the various prompts you will end up with a composer.json file that looks similar to this:
{
"name": "gocanto/simple-admin",
"description": "A package which provides a simple UI for managing users",
"authors": [
{
"name": "Gustavo Ocanto",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {}
}
Before we move on from composer we still need to do one thing, autoload our package so that Laravel can use it. To do that open the other composer.json file which is found in the root of your
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.1