Sevalla is the all-in-one PaaS for your web projects. Host and deploy your applications, databases, object storage, and static sites. Enjoy advanced deployment pipelines, a complete database studio, instant preview apps, and one-click templates. The pricing is simple: no hidden fees, no seat-based pricing, and you pay only for what you use. Get real human support from developers.

Get started now with a $50 credit at Sevalla.com.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

A beautiful PHPStorm theme

Link –

PHPStorm is the application I'm working in most of the time. So I want it to be as pretty as it can be. Right out the box PHPStorm contains two bat shit ugly themes: the default white one and the slightly better Darcula.

Fortunately for all PHPStorm users out there long time Laravel community member Dayle Rees showed us the way to the light! A few years ago he created an abundance of colour schemes that are a pleasure to the eye. You can view all the schemes on the demo page.

More recently Dayle created a new colour scheme called Material Peacock. This is what it looks like:

material

Very nice! Almost everywhere I open up PHPStorm people ask what that theme is, so I'm certainly not the only one who digs it. At this year's PHP UK Conference a PHPStorm-engineer from Jetbrains said it was the most beautiful theme he ever saw in his own product.

You find instructions on how to install the theme (made by Chris Magnussen) and the colour scheme in Dayle's Material Peacock repo on GitHub.

Read more

Integrating Algolia in a Laravel application

Original – by Freek Van der Herten – 6 minute read

A few days ago Spatie, the company where I work, launched a new website: vrijwilligerswerk.be. Translated to english it roughly comes down to workforvolunteers.be. On the website various organizations can post their jobs that can be filled by a volunteer. Volunteers have a very user-friendly way to…

Read more

Commands, events, global functions and testing

Link –

Tony Messias on the madewithlove-blog:

The other day I was listening to the FullStackRadio episode 34 which is about dealing with dependencies in Active Record models. This is a very interesting topic and they suggest a few solutions for it. I liked the suggestions and I tried to implement it differently (first try and second try).

After that, I decided to talk to my colleagues about the design implementations. And they asked “why not implementing it as a command?”. At first sight I was a bit reluctant, because I’m starting to think applications are getting more complex then it really needs. Then I decided to implement it and the end result was the best one to us. Let’s discuss it a bit.

http://blog.madewithlove.be/post/commands-events-global-functions-and-testing/

Read more

Get notified when a queued job fails

Link –

Laravel provides excellent support for queued jobs. It's very easy to put something on a queue and out of the box a lot of queue backends such as Beanstalkd, SQS and Redis are supported. Most of the time queued jobs will perform their job without any problem. But have you considered that a queued job can fail too?

Laravel can create a failed jobs table and write a record when a queued jobs fails. There is even a command to retry a failed job:

php artisan queue:retry 5

That's nice! But how do you know if there is a job that failed? Sure you could check the failed jobs table from time to time, but I promise you after a while you won't do that anymore. If you have many applications, checking all those failed job tables will get downright tedious.

To get notified when a queued job fails our intern Jolita created a package called failed job monitor. It hooks into the JobFailed-event Laravel 5.2 fires when a queued job fails. Once it is installed you will receive a mail whenever this event occurs. Integration with Slack comes built-in as well. Here's how a Slack notification looks like:

failed job

Read the full instructions on how to install and use it on GitHub.

Read more

A package to dump your database

Original – by Freek Van der Herten – 1 minute read

A few weeks ago I released a package called db-dumper. The package can dump the structure and contents of a database to a file. Here's how it can be used: Spatie\DbDumper\Databases\MySql::create() ->setDbName($databaseName) ->setUserName($userName) ->setPassword($password)…

Read more

Heroes of PHP

Link –

Following the conclusion of the 24 Days in December series on PHP, I originally posted my own 24 “Heroes of PHP”™ on Twitter.

I’m reproducing that list here, together with some additional explanation of why these individuals mean so much to me.

...

These are just some of my personal heroes, inspirations and role models, I’m sure that you have your own “Heroes of PHP”; but they all deserve thanks for the time and effort that they devote to improving our lives as PHP developers.

http://markbakeruk.net/2016/01/26/heroes-of-php-1/

Read more

Code Golf

Link –

When starting out programming many developers are quite happy when their code just works. More seasoned programmers know that making working code is just a first step. Not improving your initial code will lead to professional suicide (not my phrasing, I'm sure I've read this in a book at some point).

In an article on his blog, Colin DeCarlo demonstrates how an initial solution can be vastly improved in just a few iterations.

From time to time a friend and I play a programming game that I consider to be a version of Code Golf. Typically, the goal of Code Golf is to solve some challenge using as little bytes as possible. In the version of the game we play however, the limitation is the use of certain language features. Specifically, we try to use as little variables, conditionals and explicit loops as possible.

...

My method to accomplishing these challenges is to first write the algorithm in the simplest, most straight forward manner and then chip away at that solution until I’ve satisfied the challenge conditions.

The focus in the article is on removing conditionals, and limiting the use of variables. Keep in mind that, in most cases, this shouldn't be your main goal. Maximizing the readabilty is what your should pursue. Don't try to be too clever or terse. In some cases limiting conditionals and variables goes hand in hand with improving readability, in other cases not. It all depends on context.

Read more

Take a deep dive in Laravel's router

Link –

Over at Envato Tuts Matthew Machuga published a video explaining Laravel's router code. Going over Laravel's internal code (and other people's code in general) is always good method of learning new bits 'n' tricks.

In this lesson, we’ll explore the intricacies of Laravel Router. We’ll talk about the fundamentals of HTTP routing, before we go on to analyze some of the decisions and nuances in the design of Laravel Router. We’ll also talk about some of the awesome features that have been recently added to the router.
http://code.tutsplus.com/courses/how-its-made-laravel-router/lessons/how-its-made-laravel-router

Can't get enough Machuga? Then listen to the Full Stack Radio podcast, he's been a guest there several times. He's also one of the speakers of this year's Laracon US.

Read more

Monkey patching in PHP with Patchwork

Link –

Patchwork is a PHP library that allows you to change user defined functions at runtime. This can be incredibly handy when testing. I'm by no means a Ruby expert but I heard that in the Ruby world they do this kind of stuff all the time during testing.

Here's a simple example of what Patchwork can do:

function myCounter($array)
{
    return count($array);
}

myCounter([1, 2]); // returns '2';

//now let's change the function
Patchwork\redefine('myCounter', function($array)
{
    return count($array) ? 'a lot of items' : 'empty';
});

myCounter([1, 2]); // returns 'a lot of items";

Read the implementation docs to learn how this works behind the scenes.

Read more

Handling composers "lock file out of date" warning

Link –

Lorna Jane Mitchell explains on her blog which options you have when you see "lock file out of date" warning.

The `composer.lock` also includes a hash of the current `composer.json` when it updates, so you can always tell if you've added a requirement to the `composer.json` file and forgotten to install it.

In that case, you'll see an error message like:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

You now have three options: upgrade everything, figure it out, or do nothing.

http://www.lornajane.net/posts/2016/handling-composer-lock-file-out-of-date-warning

Read more

Messages in PHP

Link –

Matthias Noback continues his highly interesting series of posts with programming guidelines. Part four is about messages.

Besides having a type and a particular value, messages can also be categorized:
  • A command message is a request for change. One object wants to make the other object do something.
  • A query message is a request for information. One object wants to get something from the other object.
  • A document message is the response from the other object, based on the query that was sent to it.
https://www.ibuildings.nl/blog/2016/02/programming-guidelines-part-4-messages

Read more

Dead simple domain mapping in Laravel Homestead

Link –

Michael Dyrynda wrote up a follow up on my homestead tips blog post:

Now that you've setup `dnsmasq`, you can resolve `*.dev` to your Homestead machine easily, but you still need that manual step of either configuring a new domain in your `Homestead.yaml` file or using the `serve`command within the virtual machine itself.

Whilst neither of these methods take a particularly long time to complete, it's still a few seconds of repetition that can be avoided with some tweaking of your default nginx configuration using wildcard hosts.

What we'll be doing, is telling nginx to listen for anything sent to it that isn't explicitly configured and look for the domain name in your (default) /home/vagrant/Code directory.

https://dyrynda.com.au/blog/dead-simple-domain-mapping-in-laravel-homestead

Read more

What do you name the callback function?

Link –

Derick Bailey on his blog:

JavaScript practically requires callback functions to do anything asynchronous. Unless you’re talking about generators, you really can’t get away from them. Callbacks are everywhere.

...

I do use different names for the callback parameter, depending on the circumstance. I believe naming is important as it provides a set of expectations. If your code breaks the expectations of the name, people will be confused and it will cause problems.

http://derickbailey.com/2016/02/15/what-do-you-name-the-callback-function/

Read more

Typed arrays in PHP

Link –

Tim Bezhashvyly recently wrote an article in which he explains an interesting approach to make sure all items in array are of a certain type. It leverages variadic functions which were introduced in PHP 5.6

Consider this piece of code (borrowed from Tim's post):

function foo (Product ...$products )
{
/* ... */
}

In PHP 7 you can even using the scalar types, such as string and int, to make sure all elements are of that type.

Read Tim's full article here: https://thephp.cc/news/2016/02/typed-arrays-in-php

Read more

Making the PHPBenelux Conference happen

Link –

Thys Feryn, one of the organisers of the PHPBenelux conference, wrote a lengthy article about what it takes to organize a big conference.

The PHPBenelux Conference edition 2016 took place last week in Antwerpen (Belgium). As an organizer, I’m really happy with the end result. I like to think that our attendees, speakers and sponsors also enjoyed it. It’s the 7th time we organize the PHPBenelux Conference and every year we try to introduce something new. Although the 7 years of experience and the well-organized crew have made it a lot easier to organize, it’s still a lot of work.

This post gives you a behind the scenes look at what it takes to organize the PHPBenelux Conference. It will reflect our passion, our strengths and our weaknesses.

https://blog.feryn.eu/making-the-phpbenelux-conference-happen/

Screen Shot 2016-02-10 at 18.38.21

Read more

Using Cron Jobs with Laravel and AWS Elastic Beanstalk

Link –

Philip Brown on his blog:

Almost every type of application will require scheduled jobs in one form or another. This could be automated emails, generated reports, or periodic notifications to your users.

Cron Jobs are a simple way to trigger these types of processes on a given schedule. But setting up Cron Jobs in a world of ephemeral servers is not so straight forward.

In today’s tutorial we’re going to be looking at setting up Cron jobs on AWS’ Elastic Beanstalk.

http://culttt.com/2016/02/08/setting-up-and-using-cron-jobs-with-laravel-and-aws-elastic-beanstalk/

Read more