Laravel Requests data transformation

Few people know that you can piggyback on a Form Requests to transform the data you receive before getting it into the controller - this is super useful to keep controllers clean and to make validation easier.

Imagine someone sends you a line-separated email list to your API without doing any client-side transformations on their side (this can easily happen by just sending the value of a textarea) so you’ll probably want to validate that data, and use it down the line in a format that’s easier for your program to handle (array/Collection).

Read More

Hugo and Nginx multi-stage build Dockerfile

After searching for a bit I was unable to find a nice pre-made Dockerfile to serve my personal site (built on top of Hugo), some of the images I found were only Hugo build steps, some others were able to serve and build the site but they pulled the FROM:ubuntu docker anti-pattern.

So here I’ll describe what I’m doing on my final Dockerfile, it’s a really simple Docker Multi-Stage build, the first step gets the Hugo binary and builds the site, the second one copies over the public folder of the built site and serves it using the official alpine Nginx image.

Read More