What I learned from developing a Laravel Package.

  • .
  • Updated .
  • 1 views
Featured Image

After about a week of development, today I published my first Laravel Package, Laradocgen. It's a really simple package that turns Markdown files into a static HTML website to display documentation for Laravel apps. Here is what I learned.

Firstly, some context as to why I created the package. If you are reading this blog, you probably already know that I created this blog as part of my Laravel Blog Starter Kit which I also made to practice Laravel. I wanted to make some documentation for the kit and started looking into templates so I could just focus on the content. While doing this I realized something. I had already created a Markdown fileparser for the blog which reads .md files in a directory and injects them as models into an Eloquent collection, so why not build on that? I knew that while I did not need to make it into a package, I have never created a package before and I thought it would be a good experience to have.

Often programming boils down to identifying and solving a problem. The problem I was facing was not how to create a documentation site, or to create the first static site builder. I know there are countless of those already. And I know I could have just done this with plain PHP without Laravel. The problem I had was that I did not know how to create a package for Laravel and I wanted to learn.

I used Beyond Code's service Laravel Package Boilerplate to get started. I just had to fill in some details and then I could download a ZIP file of my package. Screenshot of the website

In short:

  • I learned how to create a composer package (obviosly)
  • I learned how to build a serviceprovider and bind a singleton and how to use facades
  • I learned how to use PHPDocumentor and how to properly use PHPDoc tags
  • I learned (the basics) of PHPStorm
  • I learned how to create comments in Markdown
  • I learned how to use PHP to create, modify and read files.
  • I learned (with the risk of duning-krugering myself: an intermediate level of) bash scripting for the build/test script. As well as *nix commands like sed to modify files with the power of Linux.
  • I learned how to use a local repository in composer
  • I got to practise writing tests, refactor code, document everything.
  • I also learned the value of microcommits in Git, and also how and when it makes sense to merge commits before pushing to remote.
  • I learned how to use and extend the Leauge/CommonMark package and to dynamically add extensions
  • I learned how to use CodeSniffer to validate and fix my code, and to ensure I follow the Laravel coding standardrs (PSR-2) which I also got to learn more about.