January 25, 2019
I came across an interesting problem recently while improving the Loglia Laravel client. This client is what sends your Laravel application logs to Loglia. It does this by making a HTTP request to the log ingestion endpoint for the service. The problem is that it’s common for applications to log many times during the request lifecycle, or perhaps even thousands of times in a queue job that does batch processing. All of these HTTP calls end up adding a lot of seconds to the request, slowing down page loads. It would be ideal if we could fire off the HTTP request and continue processing the...
January 3, 2019
If you’re testing form validation using Laravel Dusk, you’ve probably hit a scenario where the form submission is blocked by Chrome before it’s sent to the server because of HTML5 form validation.
HTML5 form validation blocks a submission when you add an attribute such as required to an input element, or you use
type="email". In your Laravel Dusk tests, you’ll probably see this manifesting as a client-side popup dialog in your failing test screenshots.
This is a really tricky thing to test. Since it happens completely client-side without modifying the DOM, it’s hard...
February 28, 2018
Another quick tip, this time around adding a uniqued field to a MySQL table that already has data in it using a Laravel migration.
Take the below example:
A real simple migration to add a
slug field to an existing
posts table. If you run this migration with existing data in the
posts table, you’ll come across this error:
This is because you’re not giving each row in the table a unique value to populate
slug with, so it’s failing on the 2nd row (as it has the same empty string value as the first row). You can’t set a default...
April 28, 2017
This week I had to set up something which I assumed would be trivial, but turned out to be a little more involved. So I’m jotting it down here to refer to later, or help anybody who might stumble upon it from a frantic Google search. One of the projects I’m working on right now has a staging environment on AWS Elastic Beanstalk, using a multi-container docker configuration. It’s a Laravel application, and it has some scheduled tasks that run every 1 and 24 hours. If you’re familiar with Laravel’s scheduler, you’ll know that you have to set up a single Cron job that runs every...
February 1, 2017
This is a quick tip post about a nice way to format your validation errors when working with a Laravel API.
If you’re using Laravel’s Form Requests in the context of an API, you’ll know that by default the validation errors are chucked back to the client like this:
While the above is a pretty sensible default format, it might be inconsistent with the rest of your API and thus cause confusion with your API consumers.
To build our own output, we’re going to implement our own FormRequest class that extends Laravel’s. Place it in the
November 10, 2016
In the last couple of days I’ve had an in-page modal window pop up on some websites with the title “Sponsored by [website address]”. At first I didn’t think anything of it, but this is the second time I’ve seen it now so I did some digging. The modal window looks like the below, except in your case it’s probably showing an advert. I have uBlock Origin installed so this took me by surprise. It was either malware that had been introduced to my macOS system (unlikely), or something I’ve installed in Chrome that had decided to go rogue and inject advertisements into pages,...
October 4, 2016
June 10, 2016
Note: This post was updated on 2016-07-16 to reflect a better way to achieve file uploads to an S3 bucket.
Handling file uploads sucks. Code-wise it’s a fairly simple task, the files get sent along with a POST request and are available server-side in the
$_FILES super global. Your framework of choice may even have a convenient way of dealing with these files, probably based on Symfony’s UploadedFile class. Unfortunately it’s not that simple. You’ll also have to change some PHP configuration values like
May 8, 2016
I love XKCD and I spend an embarrasing amount of time in various Slack teams (productivity tool… lol). A couple of weeks ago I went on a search for a Slack integration to insert XKCD comics based on some choice phrases. What I was envisoning was basically Giphy for XKCD comics. Imagine my surprise when I found that no such integration exists. There are some self hosted solutions floating around, but nothing that’s integrated as a Slack app and is easy to install. Lame! However, all is not lost. Being a developer who is highly motivated by nerdy side projects that offer no monetary value,...
April 14, 2016
Lately, I’ve been all about continuous integration and delivery. Since I started this blog, I’ve been looking for a better way to deploy new posts and other changes that don’t involve me using the AWS command line tools to update the files in my S3 bucket and invalidate the CloudFront cache. Some tools exist for this (such as Stout), but that still requires me to manually use a tool every time I want to deploy. Naff! Since I’ve been doing a lot of research on CI/D for use at work lately, deploying a static site strikes me as something easily achievable with continuous delivery. Of...