Remove duplicate rows from MySQL table

Introduction

Suppose that we have a MySQL table with the following fields:

SHOW COLUMNS FROM survey_responses;

---------------------------------------------------------------------------------------------------------
| id (PK) | survey_id (FK) | page_id (FK) | question_id (FK) | option_id (FK) | session_id (FK) | value |
---------------------------------------------------------------------------------------------------------

You don’t need a lot of context, you just need to …

Read More
Use language-aware cache helper in Laravel

Introduction

This little trick comes from the frustration of forgetting the language code in the cache key, inside the Cache helper of Laravel.

Suppose that in a multilingual blog you are visiting the home page for the first time, using the default language (e.g. English). If the website caches the posts to speed up the response, maybe using the following code

<?php

$posts = Cache::rememberForever('posts', function() {
    return DB::table('posts')->where( …
Read More
Laravel catch-all route for Vue Single Page Applications

Introduction

Building a complex VueJS SPA implies a lot more challenges than an ordinary application. At my job we are creating a VueJS powered SAAS platform, which shows us how powerful this library is, but also how easy it is to misunderstand things.

The Problem

This application is built upon a set of APIs provided by Laravel. We also have a few routes with static regular pages. Our RouteServiceProvider.php looks like the following:

<?php

public function map( …
Read More
Building a basic reserved area with ProcessWire

Introduction

In this tutorial we will learn how to add a simple reserved area to an existing ProcessWire website, using two handy modules, an external package and a few tricks.

In short we will build a protected page on our site, where users of a specific role can log in using their credentials, see a list of documents that the administrator made available to them, and download each one using a secure link.

Notice: If you don’t where to start with ProcessWire, I suggest …

Read More
Practical use case for React.js High Order components

Introduction

Since the React core team dropped the support for mixins, which were the standard way of sharing code between components, the use of composition over inheritance has become the right way for building user interfaces.

A High Order Component (HOC from now on) is a pattern for reusing component logic that has evolved to maturity. It’s used throughout many famous libraries like Redux or React-Router, and it’s a direct consequence of React’s compositional …

Read More
Split char-separated values in MySQL

Introduction

Recently I needed to extract a list of URLs from a MySQL table. All those URLs were inserted in a single TEXT column, however they were all separated by semicolons. The situation was more or less like the following:

SELECT * FROM links

---------------------------------------------------------------
| id | urls                                                   |
---------------------------------------------------------------
|  1 | http://first.link;http://second.link …
Read More