Hi, I'm Liam

I'm a full-stack software developer that loves working with PHP, JavaScript, Laravel and Vue.

Here you can find my latest blog posts as well as any useful tips & tricks, opinions, or other miscellaneous things I might share.

2022 In Review

by Liam Hammett · 4 minute read

It feels weird to write a “2022 in review” post on a blog where I haven’t posted at all for the year in question, let alone at the very end of January when most people write posts like this at the start of the year, but hey, and it’s better to write something late rather than never!

So, why haven’t I been as active in 2022?

Unfortunately, towards the start of 2022, I’d hit minor burnout. It was nothing serious, but it was enough to kill the momentum I had built up writing and contributing to open source beforehand. It’s much easier to keep a ball rolling than to speed it up.

In 2021 I decided to take a promotion to become a Tech Lead and tread the engineering management path. The transition from being a 100% individual contributor to splitting time between management and my desire to still act as an individual contributor wasn’t immediately apparent to me. It took me some months to get to grips with that and find a flow I’m happy with, and I am glad to say I’ve managed to reach a balance that works for me.

While most of my time over the last year was spent growing and doing my day job, I did achieve some personal goals:

  • I’ve taken longer holidays than I have for a long time and used them to travel and see some lovely places, visiting remote parts of Scotland and Norway while also spending a lot of time in Germany. It’s been nice to travel again since the pandemic and see some places I’ve wanted to visit my whole life. It’s also been nice to take the time away from work and tech altogether a couple of times to clear my head.
  • As someone who enjoys the variety of food, in 2022, I set myself a goal to try 50 new foods (basically one per week) that I hadn’t tried before. While I didn’t quite meet this goal (44/50), it was a great chance to try a lot of cuisines I had yet to try before and learn many new cooking techniques along the way. I’ve definitely fallen in love with Korean food a lot more!
  • The biggest thing that happened to me this year, while in Norway with my girlfriend, I proposed to her and am ecstatic to say we’re now engaged!

What’s 2023 got in store?

As we advance into the next year, I want to regain momentum and return to things I thoroughly enjoyed doing. I’ve been using this start-of-the-new-year rush to get the ball rolling so that it’s easier to keep the momentum throughout the year.

So, in 2023 I want to…

  • Write a lot more! I have drafted some blog post ideas I’ll follow up on, and we’re starting an engineering blog at work so I can justify spending some time at work towards writing.
  • Write more about localisation with l10n.expert. I have so much to say about localisation and many parts of it written already that I need to share.
  • Update all of my open-source projects. I acknowledge that I have neglected some of them and let issues pile up, but I want to get back on top of that and release some new projects and contribute some ideas to some of my favourite tools.
  • Get back into the talk scene by attending meetups/conferences and giving talks myself. I’ve submitted to a handful of CFPs already and will have a keen eye out for any others that come up.
  • And of course, I intend to marry the love of my life this year too!

I’m looking forward to the rest of the year, here’s to 2023!

Read more…

Laravel Blade Internals (Video Series)

by Liam Hammett · 1 minute read · #php #laravel

In this short video series, I take you through Laravel Blade and some things I’ve picked up from using it extensively for a long time.

We’ll see how to make Blade work from plain PHP, the additional things it does under-the-hood, how to disable the view cache, extend Blade and write your own custom directives that work reliably and effectively. Come along for the ride and watch the series.

Read more…

Unconventional Autoloaders (Talk)

by Liam Hammett · 1 minute read · #php #talk

We use autoloaders in PHP all the time, but if you change your mindset a little, you’ll find they can do a lot more than you might’ve thought. We’ll be taking a look at using some unconventional techniques, we can use autoloaders to take PHP a step further, introducing interesting and exciting new functionality PHP natively doesn’t support.

Read more…

Translated Text in Source Code

by Liam Hammett · 8 minute read · #localisation

There are a few different ways to handle translated text in your codebase, but here we’ll cover 2 of the more common approaches; using the full text in your source code, and using translation keys.

⚠️ Note: This is an excerpt from my upcoming book & course about localisation for software developers. If you want more of this kind of content, sign up to the newsletter at l10n.expert to get more excerpts before the full release.

Full text in source code

Read more…

Announcing the Livewire.run Newsletter

by Liam Hammett · 1 minute read · #livewire #newsletter

If you’ve not heard already, I announced on Twitter the other day that I’ll be starting a Livewire-focussed newsletter.

I plan to use this as a space to help make people aware about all the new minor features in Livewire that don’t get their own big announcement, as well as general community updates and 🔥 tips to get the most out of Livewire.

Read more…

Protecting Against Infinite Gmail Addresses Using Regex

by Liam Hammett · 3 minute read · #php #regex #gmail

You might be aware that one Gmail account could have an almost unlimited number of email addresses associated with it, to no effort of the user who owns the account. If you’re not aware of this, check out my post below explaining it:

If you’re thinking to yourself “how can I protect against users abusing this in my own applications?” - you’re in luck, because that’s exactly what we’ll be covering here.

Read more…

Compound Colour Utilities with TailwindCSS

by Liam Hammett · 5 minute read · #tailwind

When creating UIs with TailwindCSS, I often find myself writing the same few utilities together on the same elements all the time. This is why I often end up composing some common components, like a .button and .form-input classes.

In my mind, however, a “component” is a fully-formed set of styles for an element - something like a button may affect the colours, padding, border radius, text size and more - styles that are not necessary to be coupled together to still have a usable element.

But what do you do if you want to modify something that’s tightly coupled together, like the colours? If your default element has black text and you set a dark background utility, you probably don’t want it to keep having black text - coupling another text-colour utility to it.

Read more…

Unconventional PHP (Talk)

by Liam Hammett · 1 minute read · #php #talk

You might think you know PHP, but if you dig below the surface you might find it can do more than you knew. Beyond the documented features, there lies a world of tricks, hacks and other techniques that can allow PHP to go a step further.

In this talk we’ll look outside the box at some things PHP provides like references, autoloading and magic methods and explore how using them in an unconventional way can benefit our own code.

Read more…

Inline Parameters Extension for VSCode

by Liam Hammett · 7 minute read · #php #vscode #javascript

Does the needle or haystack go first? What’s the 12th argument for that function do again? Is this function variadic or does it need an array?

If you’ve ever found yourself asking any of these questions and happen to use VSCode, maybe my new Inline Parameters extension will help you out!

Read more…

Laravel TALL Stack Preset

by Liam Hammett · 3 minute read · #laravel #tailwind #alpinejs #livewire

Do you enjoy using TailwindCSS, AlpineJS, Laravel and Livewire together?

Well you’re in luck! Along with Dan Harrin and Ryan Chandler, we’ve just released a preset that can provide all of this out-of-the-box with sensible defaults to get you up and running with these technologies in a flash.

Read more…

Static Constructors in PHP

by Liam Hammett · 5 minute read · #php

“Static constructors” are a concept a lot of object-oriented programming languages support - although, unfortunately, PHP does not.

If you’re not familiar with the concept, a static constructor is just a method the developer can define on a class which can be used to initialise any static properties, or to perform any actions that only need to be performed only once for the given class. The method is only called once as the class is needed.

The C# guide about static constructors is a good resource to see how another language handles these, however we’ll cover the important bits below.

Read more…

Laravel Testing - CSS Selector Assertion Macros

by Liam Hammett · 7 minute read · #laravel #testing

Laravel offers some very useful ways to test that your pages are being rendered with the right content by making assertions directly on the response object.

It’s such an elegant and fast way to be sure your application is doing what you want, but doesn’t necessarily always do what you might want.

A test doing this in Laravel may look like the following, creating an article then making sure the title of that article shows on the listing page:

Read more…

Laravel Mixins

by Liam Hammett · 4 minute read · #laravel

Have you ever wished that a PHP class had another method on it that you’d like to use? Laravel makes this dream come true through its concept of “Macroable” classes.

Macroable itself is the name of a trait Laravel comes with that is applied to many of the framework’s own classes.

This trait allows you to call a static “macro” method at runtime to add a new method to the class by executing a closure. Behind the scenes, it will use the magic __call() and __callStatic() methods PHP provides to make the method work as if it were really on the class.

Read more…

Black Friday & Cyber Monday 2019 Deals for PHP & Laravel Developers

by Liam Hammett · 4 minute read · #laravel

Black Friday and Cyber Monday deals have already started for 2019, and if you’re a PHP or specifically Laravel developer, there’s a lot to look forward to, especially if you’re looking to expand your knowledge and pick up some new skills on the cheap.

In this page I’ll be keeping you up-to-date with the best and latest deals to keep an eye on - it’s the only time of year with these kinds of huge price drops, so don’t miss out.

If you want to see the kind of deals that were up for grabs last year and what you can expect to come over the next few days, check out last year’s post.

Read more…

Textarea Slots in Vue Components

by Liam Hammett · 3 minute read · #vue

If you’ve ever tried to build a custom component to wrap around the <textarea> element with Vue, you’ll find that it’s not as simple as you first think to keep the behaviour the same as the native element.

In this post I’m going to quickly show the problem that you’ll likely run into, and a simple solution for it.

Let’s take a look…

Read more…

Run and stop multiple long-running commands from Bash with a trap

by Liam Hammett · 7 minute read · #bash #laravel #cli

Sometimes when working on a project, I’ll always want to run a handful of commands at the same time, some of which may return when they’re done, others might be long-running, like watchers or services actively exposing ports.

This is something that might seem simple to do with a basic Bash script at first, but what if your script has multiple processes running side-by-side and you want to be able to stop them all at once too?

Here we’re going to take a look at how we can achieve this with Bash traps and the single-ampersand operator.

Read more…

Private Constructors

by Liam Hammett · 5 minute read · #php #oop

Private constructors are a pattern found in object-oriented programming languages that prevents the class from being instantiated, except by itself.

The first time I saw this pattern in my programming career, I was confused. It wasn’t immediately apparent why such a feature would ever be beneficial in the real world. How are you meant to use the class if it can’t be instantiated? Why even bother defining a constructor at all if it can’t be called?

It turns out there are a handful of uses that private constructors can lend themselves to. Here I’m going to go over a few purposes they serve. The examples are in PHP but should transfer to any language that supports this feature.

Read more…