Package template helps to create a structure of package with single command. It also provides other commands to generate files just as in laravel.
Use the package manager composer to install PackageTemplate.
composer require anandmainali/packagetemplate
This package implements Laravel auto-discovery feature. After you install it, the package provider and facade are added automatically for laravel >= 5.5.
After installation, you have to publish config file.
php artisan vendor:publish --tag=package-config
This will generate package.php
file inside the config folder.
<?php
return [
/**
* Main folder to holds all the packages. Contains packages with VendorName.
*/
'path' => 'packages',
/**
* The VendorName will be generated inside the main folder.
*/
'vendorName' => "VendorName",
/**
* These are the folders that will be generated while creating package.
*/
'folders' => [
'controllers', 'database/migrations', 'models', 'policies', 'resources/views', 'routes'
],
/**
* These are the files that will be generated while creating package.
*/
'files' => ['routes/web']
];
Now, you can start building your package. To generate package,
php artisan create:package PackageName
And, all the files and folders you specified in config.php
will be generated.
Note:- The PackageName
is used to generate files inside the package.
create:model ModelName PackageName
create:controller ControllerName PackageName --r //--r is optional. It is used to create resource controller.
create:migration MigrationName TableName PackageName
create:policy PolicyName PackageName
create:command CommandName --command=command:name PackageName