Get the full path of a File using the Storage facade on Laravel

Introduction

This post is just a reference for the various ways of retrieving the full path of a file using the Storage facade in Laravel.

Under the hood the Storage facade it uses the Flysystem PHP Package by Frank de Jonge, allowing the developer to use the same API with different filesystem drivers (Local, SFTP, Amazon S3, Rackspace and so on).

In this post I’m interested in getting the full path of a file. I will use the local driver, whose methods are relative to the root …

Read More
Nullable objects using JavaScript proxies

Introduction

JavaScript proxies are an ES6 (aka ES2015) feature that lets you wrap an existing object and intercept any access to its attributes or methods, even if they do not exist.

var proxy = new Proxy({ name: "John Doe" }, {
    get: function(target, property) {
        if (property in target) {
            return target[property];
        } else {
            return "Nope!";
        }
    }
});

console.log(proxy.age);         // "Nope!"
console.log(proxy.name); …
Read More
Handling breadcrumbs with VueX in a VueJS Single Page Application

Introduction

At work we are building a complex Single Page Application with VueJS, VueX and VueRouter. As soon as it started to get bigger we found the need to add breadcrumbs to the main interface, in order to indicate to the user exactly where he/she is and to provide an effective navigation mechanism.

At first we searched for existing solutions and libraries, however we only found bits of inspiration, but nothing really ready to use, so we decided to roll out our own solution for the …

Read More
Manage content in a ProcessWire website using Telegram

Introduction

In this tutorial we will learn how to manage content in a ProcessWire website using a Telegram bot.

Today responsive bots are on everyone’s mouth, so I decided to take a deep dive into this new (at least for me) world to learn something new, but also to build something useful using my favourite CMS.

Notice: If you don’t where to start with ProcessWire, I suggest you to look at my 4-part series “How to build a basic webiste with ProcessWire”.

The idea …

Read More
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 know …

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