This Yeoman generator will quickly and easily scaffold a Laravel package, getting you up and running within a few seconds.
It will generate the necessary files such as a service provider and a composer file, while also generating placeholder directories for migrations, translations etc.
The service provider will be configured with all the correct settings for loading and/or publishing your assets. Just uncomment what you need and you're done.
For a full overview of the scaffolded files, have a look over here.
If you haven't done so already, install the Yeoman generator:
npm install -g yo
After that, install the scaffolder generator:
npm install -g generator-laravel-package-scaffolder
Run the following command:
yo laravel-package-scaffolder
and follow the instructions.
Given a package with the name "MyPackage", the resulting package will have the following directory structure and files:
.
├── README.md
├── .gitignore
├── composer.json
├── config
│ └── my-package.php
├── database
│ └── migrations
│ └── .gitignore
├── phpstan.neon
├── phpunit.xml
├── public
│ └── .gitignore
├── resources
│ ├── lang
│ │ └── .gitignore
│ └── views
│ └── .gitignore
├── routes
│ └── web.php
├── src
│ ├── Console
│ │ └── Commands
│ │ └── MyPackageCommand.php
│ ├── Providers
│ │ └── MyPackageServiceProvider.php
└── tests
└── TestCase.php
If you want to use your package on the local filesystem in a Laravel app for development purposes, include the package in the app's composer.json file:
"repositories": [
{
"type": "path",
"url": "path/to/your/package/root"
}
],
Next, add your package to the require section of the app's composer.json file:
"require": {
"vendor/package": "*"
}
After the composer.json file has been updated, run the composer update command:
composer update
This will symlink the package into the app's vendor dir.
Note: If you update your package's composer.json file, you need to run the composer update command again to update the app's autoloader.
This is only necessary for the composer.json file. Changes in any other files in your package will be automatically updated thanks to the symlink.
This generator automatically adds PHPUnit for unit testing and PHPStan for static analysis. Both are added to the composer.json scripts
attribute. You can run them using:
composer run test
composer run analysis
See CONTRIBUTING.md.
See CHANGELOG.md.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The generator is fully backed (well, almost fully backed 😐) by unit tests. The test runner of choice is Jest.
jest
jest --coverage --coverageDirectory=coverage/jest