Run and debug Github actions locally

Introduction

The GitHub actions service was launched exactly one year ago (November 2019).

Since then it has got lots of positive feedback and it has quickly convinced many developers to shift the integration and deployment pipelines of their applications from external CI/CD services to GitHub. Having the possibility to build, test and deploy code from a central service greatly helps developers, who are notoriously lazy (or at least, I am 😔).

Usually when creating a new GitHub action, you …

Read More
Reduce the size of a large MySQL dump file

Introduction

I already mentioned in a previous post that sometimes at work we have to deal with very large mysqldump backups of our production MySQL databases. A couple of days ago I had to restore locally a database from a 2.6 GB dump file gzipped, which means that the full database was almost 27 GB large.

Running the import command

$ mysql -u homestead -psecret mydatabase < large-dump.sql

completely killed my MySQL development instance (I’m using Laravel Homestead), forcing me …

Read More
Send email in Laravel without using Mailables

Introduction

I keep forgetting how to send an email in Laravel without using Mailables. The the documentation does not help so I’m writing this down here for future reference.

The following examples are based on the code of the Mailer class

How to

In order to send a raw message (in plain text) you can use the raw method of the Mail facade:

<?php

Mail::raw('Hello, welcome to Laravel!', function ($message) {
  $message
    ->to(...)
    ->subject(...);
});

On the …

Read More
Implement dynamic custom messages from validation errors in Laravel

Notice: the following article takes into consideration Laravel versions lower than 5.5. After that it is easier to use custom validation rules

Introduction

Laravel provides different approaches to validate your application’s incoming data.

My favorite method to validate input data in controllers is to create Form Requests: custom request classes that contain authorization and validation logic. They allow you to keep your controllers as clean as possible, because the logic is …

Read More
Remove Laravel Mix during tests

Introduction

Laravel Mix is a handy Webpack wrapper for frontend asset building pipelines. It definitely helps any Laravel developer which wants to avoid the pain of Webpack setup and configuration.

For example, the following 2 lines:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

will apply

  • module bundling, minification, and concatenation using the app.js JavaScript file as entry point, writing the output …
Read More
Parse log files with AWK

Introduction

Not everyone can afford (or have the need of) an ELK stack for analyzing logs. Sometimes reading files from the command line is the fastest and most straightforward way to spot a problem, if you know how to filter the data.

AWK is an excellent UNIX tool (actually it’s an interpreted programming language) for processing structured data, for example rows and columns generated by applications and tools.

The word AWK comes from the initials of the language’s three …

Read More