Skip to content

Laravel package development

Notes

If any point, something doesn't make sense, or you made some changes in composer.json of your package: do these (in your test laravel project, not the package project) to ensure the slate is clean: - Clear bootstrap/cache folder content, don't delete the folder - Delete vendor folder - Delete composer.lock - composer install - composer dump-autoload - Re-require your package - If none of these work: call an exorcist. Trust me, it worked.

Resc

  • https://laravelpackage.com/02-development-environment/
  • [!] https://github.com/spatie/package-skeleton-laravel

Steps

  1. git init (duh)

  2. composer init

  3. add .gitignore

    /vendor/
    /.idea/
    composer.lock
    **/coverage/
    .phpunit.result.cache
    /.phpunit.cache/
    /clover.xml
    

  4. Create basic folder structure

  5. /src
  6. /tests

  7. Add orchestra. Enables laravel mocking environment. For type-hint and stuff.

  8. Integrate into an actual laravel project for local development and testing purposes

  9. composer create-project laravel/laravel example-app
  10. cd example-app
  11. composer install
  12. Add repository target for your package, do this in the laravel project's composer.json:
    "repositories": [
         {
             "type": "path",
             "url": "../path-to-your-package",
             "options": {
                 "symlink": true
             }
         }
     ],
    
  13. composer install
  14. composer require username/package-name:dev-master (username/package-name should be identical with name key in your package's composer.json.
  15. composer install
composer require --dev "orchestra/testbench"