├── .gitignore ├── .php_cs ├── README.md ├── composer.json ├── config └── config.php ├── phpunit.xml.dist ├── src └── LaravelPackageTemplateProvider.php └── tests ├── ExampleTest.php └── TestCase.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | composer.lock 3 | .php_cs.cache 4 | .phpunit.result.cache 5 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') 5 | ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') 6 | ->append(['.php_cs']); 7 | 8 | $rules = [ 9 | '@Symfony' => true, 10 | 'phpdoc_no_empty_return' => false, 11 | 'array_syntax' => ['syntax' => 'short'], 12 | 'yoda_style' => false, 13 | 'binary_operator_spaces' => [ 14 | 'operators' => [ 15 | '=>' => 'align', 16 | '=' => 'align', 17 | ], 18 | ], 19 | 'concat_space' => ['spacing' => 'one'], 20 | 'not_operator_with_space' => false, 21 | ]; 22 | 23 | $rules['increment_style'] = ['style' => 'post']; 24 | 25 | return PhpCsFixer\Config::create() 26 | ->setUsingCache(true) 27 | ->setRules($rules) 28 | ->setFinder($finder); 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Package Repository Template 2 | A bare bones respository template for developing Laravel packages. 3 | ### How To Use 4 | Use the green "Use this template" button above to create a new repository based on this repo. You'll get a fresh repository reflecting the code as it is right now in this repo, but with a fresh commit history. 5 | 6 | After you've done that, you have some editing / refactoring to do. Depending on your IDE the instructions and difficulty of this will vary a bit. But however you accomplish them, here are your steps: 7 | 8 | 1. Edit composer.json to change the vendor/packagename line, the description, the author name, and the author email. Also update the autoload blocks to reflect your vendor namespace and package name. 9 | 10 | 2. Rename LaravelPackageTemplateProvider.php to be {YourPackageName}Provider.php and change the class name inside to match. Change the namespace to match your vendor namespace. 11 | 12 | 3. Go to tests/TestCase and change the name of the loaded service provider to match your package name. 13 | 14 | 4. Run the tests. There should be one test and it should pass. If that happens, you know you at least haven't broken the test setup and should be ready to start building something great. 15 | 16 | ### Linting and Testing 17 | 18 | ```shell script 19 | composer test:unit # Runs PHPUnit 20 | composer lint # Runs php-cs-fixer to fix your coding style 21 | composer test # Runs lint and then test:unit 22 | ``` 23 | 24 | ### Acknowledgements 25 | 26 | I started off writing packages with the help of Marcel Pociot's excellent [Laravel Package Boilerplate](https://laravelpackageboilerplate.com/#/) and I purchased and used his course on package development. Without those two things I'd never have gotten to be nearly as proficient in package develpment as I am. If you are just starting out, I strongly recommend using those vs using this template or starting from scratch. 27 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grosv/laravel-package-template", 3 | "description": "A repository template for Laravel packages", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Ed Grosvenor", 9 | "email": "ed.grosvenor@wickedviral.com" 10 | } 11 | ], 12 | "minimum-stability": "dev", 13 | "prefer-stable": true, 14 | "require": { 15 | "php": "^7.3", 16 | "illuminate/support": "^7.0|^8.0" 17 | }, 18 | "require-dev": { 19 | "orchestra/testbench": "^5.0", 20 | "friendsofphp/php-cs-fixer": "^2.16" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Grosv\\LaravelPackageTemplate\\": "src/" 25 | } 26 | }, 27 | "autoload-dev": { 28 | "psr-4": { 29 | "Tests\\": "tests/", 30 | "App\\": "vendor/orchestra/testbench-core/laravel/app" 31 | } 32 | }, 33 | "extra": { 34 | "laravel": { 35 | "providers": "Grosv\\LaravelPackageTemplate\\LaravelPackageTemplateProvider" 36 | } 37 | }, 38 | "scripts": { 39 | "lint": "php-cs-fixer fix -v", 40 | "test:unit": "phpunit", 41 | "test": [ 42 | "@lint", 43 | "@test:unit" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | tests 15 | 16 | 17 | 18 | 19 | src/ 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/LaravelPackageTemplateProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-package-template'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/ExampleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | set('database.default', 'testing'); 28 | $app['config']->set('app.key', 'base64:r0w0xC+mYYqjbZhHZ3uk1oH63VadA3RKrMW52OlIDzI='); 29 | } 30 | } 31 | --------------------------------------------------------------------------------