Nested Language Files in Laravel 5

Posted 28th May 2016

In ear­lier ver­sions of Lar­avel, you were able to use dot nota­tion to refer to lan­guage lines in sub-​directories of your trans­la­tions directory.

So in other words, given the fol­low­ing file structure:

resources
  lang
    en
      site.php
      admin
        settings
          site.php

…you could refer to a line named title in resources/lang/en/admin/settings/site.php like this:

admin.settings.site.title

This no longer works in Lar­avel 5. It’s entirely pos­si­ble, how­ever — it’s just not obvi­ous, nor par­tic­u­larly well documented.

All you need to do is use forward-​slashes, for example:

admin/settings/site.title

Micro; a Replacement for Emacs / Vim / Nano?

Posted 20th April 2016

I’m a big Sub­lime Text fan, but I also spend a lot of time in the ter­mi­nal. Nat­u­rally that involves some time in a text edi­tor; the usual sus­pects are Vim, Emacs and Nano. Per­son­ally I pre­fer the lat­ter; it has what I con­sider to be “sen­si­ble” key-​bindings. So CTRL-X to quit rather than, well, a Kon­ami code.

As use­ful as Nano is, there’s a huge dis­con­nect between that and Sub­lime Text. While a terminal-​based edi­tor is unlikely to serve as an IDE, things like syn­tax high­light­ing and con­trol over tab-​spacing would be a bonus.

Well, Micro pro­vides just that. Take a look at the screen­shot below, which shows it in action.

Pretty Pagination URLs with Laravel 5

Posted 18th April 2016

It’s entirely down to per­sonal pref­er­ence, but a com­mon ques­tion is how to cre­ate “pretty” pag­i­na­tion URLs.

What I mean by that, is instead of some­thing like this:

example.com/blog?page=2

You end up with a URL which looks like this:

example.com/blog/page/2

Here’s how to do just that in Lar­avel 5, using this pack­age.

For the pur­poses of this post I’m assum­ing you already have a con­troller method which uses pag­i­na­tion; if you don’t then just cre­ate it as nor­mal (the doc­u­men­ta­tion is here if you need it), then come back.

Installing the Package

How to Detect Ad-Blockers

Posted 18th February 2016

Source Code | Demo

There’s no doubt about it, the use of ad-​blockers is on the rise. Feel­ings run high on the issue; with web users argu­ing that adver­tise­ments are beyond con­trol, that they have become too intru­sive and that their pri­vacy is being under­mined. Internet-​based pub­lish­ers, mean­while, argue that adver­tise­ments are a cru­cial — in many cases, only — source of income online, and that ad-​blockers threaten their very existence.

That’s not to say that one must sit in either camp — those of us who are involved in pro­duc­ing con­tent still browse the ‘Web as con­sumers, and may feel with some jus­ti­fi­ca­tion that on some sites, the use of adver­tise­ments is ruin­ing the online experience.

Generating Website Screenshots with PHP

Posted 25th January 2016

In this post, I’m going to intro­duce a PHP pack­age I recently released for gen­er­at­ing screen­shots of web pages. It’s pretty straight­for­ward to get up-​and-​running, as I’ll demonstrate.

Why Gen­er­ate Screenshots?

There are a num­ber of rea­sons you may wish to gen­er­ate screen­shots. My moti­va­tion behind the pack­age orig­i­nally was to build a sim­ple “direc­tory” of web­sites, using screen­shots to illus­trate the sites.

Screen­shots are also use­ful in test­ing; you could even run a script to peri­od­i­cally gen­er­ate a screen­shot of one of the sites you main­tain in order to check that every­thing is ren­der­ing okay.

What are the Options?

Before I intro­duce the pack­age, it’s worth men­tion­ing that there are a num­ber of third-​party ser­vices which make it even eas­ier to gen­er­ats screen­shots such as Brow­shot, URL2PNG, Shrink the Web and Url­box — but it’s worth not­ing that these are all paid ser­vices. If you’d rather do it your­self, or do it on-​the-​cheap, you might like to try out my package.

Using Pikaday with Angular Formly

Posted 21st December 2015

Pika­day is a great lit­tle date selec­tor plu­gin. Whilst the Pika­day Angu­lar plu­gin makes it easy to inte­grate into an Angu­lar appli­ca­tion, there’s slightly more work involved in get­ting it work­ing with Angu­lar Formly.

If you haven’t used Formly, it’s essen­tially a frame­work for cre­at­ing forms declar­a­tively; rather than writ­ing out its HTML by hand. It takes care of ren­der­ing the rel­e­vant con­trols and their labels, enables you to attach val­i­da­tion and it will inject error mes­sages for you, and a num­ber of other features.

The prob­lem with using Pika­day with Formly is that you’re prob­a­bly going to want to trans­late the dis­play value of the plu­gin into a for­mat more suit­able for stor­age. For exam­ple in one form you might dis­play “12 Jan­u­ary 2016″ but want it bound to a model in ISO 6031 format.

Easy Jekyll Deployment with Grunt and Git

Posted 12th September 2014

I’ve recently re-​built this site using Jekyll, for rea­sons I’ll go into in another blog post. I wanted to make deploy­ing changes really, really easy. In this post, I’m going to detail my approach.

Host­ing

Jekyll plays nicely with Github Pages. How­ever, I haven’t taken advan­tage of it, for two rea­sons. The first is that I have a num­ber of unsup­ported plu­g­ins, so I can’t take advan­tage of their auto­matic Jekyll build­ing process. That’s not nec­es­sar­ily an imped­i­ment to using Github Pages, since there are workarounds. A big­ger issue is that you cur­rently can­not use HTTPS with a cus­tom domain, which is sud­denly really impor­tant as far as search rank­ings go, fol­low­ing Google’s recent announce­ment.

Building Applications with Backbone and Laravel: JST

Posted 13th April 2014

You might well be used to devel­op­ing Back­bone views like this:

MyApp.Views.SomeView = Backbone.View.extend({    
  template: _.template('<ul><% _.each(items, function(item){ %><li><%= item %></li><% }); %></ul>'),    
  el: '#some-element',

This is all fine and well for sim­ple struc­tures, but can quickly get unwieldly if you’re build­ing markup of any sig­nif­i­cant size or com­plex­ity. It can also lead to all sorts of issues around readability.

One alter­na­tive is to put more com­plex tem­plates into sep­a­rate HTML files:

// file: folder/template.html

<ul>
 <% _.each(items, function(item){ %>
 <li> <%= item %> </li>
 <% }); %>
</ul>

More Articles and Tutorials

Posted 12th April 2014

I’ve had a few more arti­cles and tuto­ri­als pub­lished in the past few days, with a num­ber to come later this month. Here’s a quick run-​down of the arti­cles I’ve had pub­lished in the past cou­ple of weeks.

Abstract File Sys­tems with Fly­sys­tem, Sitepoint

An intro­duc­tion to Fly­sys­tem, a PHP library which pro­vides devel­op­ers with a layer of abstrac­tion over file stor­age sys­tems includ­ing stan­dard local files, online ser­vices such as Drop­box and Cloud Files and remote stor­age mech­a­nisms such as FTP.

Intro­duc­tion to Jade­PHP, Sitepoint

Jade is a tem­plat­ing lan­guage often found in the JavaScript world. Heav­ily influ­enced by Haml, it pro­vides an extremely con­cise way of defin­ing your XML-​based markup. Jade­PHP brings it to PHP, and in this arti­cle I take it for a test-​drive.