Gilbert Pellegrom

Gilbert Pellegrom

Software Engineer and Web Developer from Scotland

Path Copy 2 Created with Sketch.

Category: Development

AJAX in WordPress Themes

Posted on

For some reason, it seems really hard to find a nice, simple, copy-and-paste-able resource for explaining how to do AJAX requests in WordPress themes the-right-way™. So here it is. Backend Let’s add the function that will return the AJAX response from the backend. This is normally added to the theme functions.php file: Notes: We need…

Coming Around to Utility First CSS

Posted on

This week I’ve been playing with Tailwind, which is a “Utility-First CSS Framework for Rapid UI Development”. At first I was skeptical of the benefits of “utility-first” CSS but I’m pleased to say that after using Bootstrap 4 for a while (which contains some utility classes) and Tailwind for a week I’m convinced that utility-first…

Custom Validation Attributes in Laravel

Posted on

Recently, I was working on some Laravel validation that used the array syntax to validate fields. For example: However, in this case the error message that is returned looks like this: Not ideal. The Laravel docs cover how to customize the error messages for rules but not for the attribute names themselves. It turns out…

Setting up Font Awesome 5 in Laravel using Vue.js

Posted on

So you have a Laravel app set up and you want to use the new Font Awesome 5 goodness in your Vue.js components. Here’s how you do it. 1. First, install the required packages: We’re going to use the official Vue component to display the Font Awesome icons in this case. 2. Next, import the…

My problems with utility-first CSS

Posted on

If you’ve not already read it yet, you should read Adam Wathan’s article on how he reached the conclusion that using utility classes was the best way to build consistent components in CSS. As I read the article I followed his conclusions and agreed with his justifications. It sounded like a very reasonable solution. However,…

Modifying Variables in PHP Closures

Posted on

This one caught me out yesterday. If you use a variable in a PHP closure and try and modify it inside the closure, you will find that the variable outside the closure is not modified. You must pass the variable by reference for it to work. Turns out that when ‘importing’ variables to a closure’s…

Convert the Laravel Spark invoice email to a Mail Notification email

Posted on

Recently when customizing the invoice email template for Laravel Spark I noticed that it didn’t have any styles applied (raw HTML emails are a bit 1999). Given how good the new Mail Notifications look in Laravel 5.3 I figured it would make sense to convert the existing invoice email template to the new Mail Notifications.…

Running PHPUnit Tests in Docker

Posted on

Recently I came across the situation where I needed to run the PHPUnit tests for the project I was working on in PHP 5.6 as they were failing in Travis. The project was a Laravel project and so was running in a Homestead box using PHP 7. For development of other sites I use Laravel…

Backing Up Laravel Homestead Databases

Posted on

Laravel Homestead is an awesome tool for building Laravel sites. However, sometimes it would be nice if when you did a vagrant destory you wouldn’t lose all of the information in your databases. Or in my case, if you database crashes and you can’t get it back up, it would be great if you had…

Conditional Breakpoints in PhpStorm

Posted on

Here is a quick tip: Have you ever been debugging code in a loop and only wanted to trigger a breakpoint if a specific condition is met? In PhpStorm it’s actually very simple. Right click on the breakpoint and add a “Condition”.