Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Stay up to speed with PHP by reading these feeds

Original – by Freek Van der Herten – 1 minute read

In the PHP ecosystem we're blessed with so many people blogging about their favourite language. Everyday new interesting content on PHP gets posted somewhere on the web. Visiting each blog separately to see if new content has been posted is quite tedious. Luckily this problem has been solved long…

Read more

Free Wildcard SSL Using Forge + Cloudflare

Link –

If you need a free SSL certificate Let's Encrypt seems like the obvious way to go. But the installation and renewal process of Let's Encrypt surely has it's caveats. An alternative to Let's Encrypt is to use a free certificate issued by Cloudflare. On his blog Taylor Otwell published a post explaining how to request and install such a certificate.

I personally prefer to use Cloudflare, another service that offers free SSL certificates, as well as a variety of other free and paid services that are useful for web developers. I prefer Cloudflare because: - Cloudflare doesn’t require any renewal process to ever run on my server. LetsEncrypt renewals must run on my server at least every 3 months and that’s just one more thing that sometimes can (and does) go wrong. - Cloudflare supports wildcard sub-domains.

https://medium.com/@taylorotwell/free-wildcard-ssl-using-forge-cloudflare-ab0ebfbf129f

Read more

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.

Tweaking Eloquent relations – how to get latest related model?

Link –

Jarek Tkaczyk demonstrates how you can use a helper relation to eager load specific models.

Have you ever needed to show only single related model from the hasMany relationship on a set of parents?

Being it latest, highest or just random, it’s not very clever to load whole collection using eager loading, just like running query per every parent.

Of course you can do that better, and now let me show you how.

https://softonsofa.com/tweaking-eloquent-relations-how-to-get-latest-related-model/

Read more

A package for snapshot testing in PHPUnit

Link –

My colleague Sebastian recently released a new package called phpunit-snapshot-assertions. In a new post on his blog he tells all about it.

The gist of snapshot testing is asserting that a set of data hasn’t changed compared to a previous version, which is a snapshot of the data, to prevent regressions. The difference between a classic assertEquals and an assertMatchesSnapshot is that you don't write the expectation yourself when snapshot testing. When a snapshot assertion happens for the first time, it creates a snapshot file with the actual output, and marks the test as incomplete. Every subsequent run will compare the output with the existing snapshot file to check for regressions.

https://medium.com/@sebdedeyne/a-package-for-snapshot-testing-in-phpunit-2e4558c07fe3

Read more

How to set up your Laravel application for zero-downtime deploys

Link –

On his blog Matt Stauffer published a new post explaining the steps required to deploy your app without any downtime.

The reason you're getting zero-downtime deploy from these tools is because the entire deploy process—clone, composer install, etc.—doesn't happen in the directory that is currently serving your site. Instead, each new release gets its own separate "release" directory, all while your site is still being served from its current "release" directory.

https://mattstauffer.co/blog/how-to-set-up-your-laravel-application-for-zero-downtime-envoyer-capistrano-deploys

In my own projects I handle these capistrano like deploys using a custom Envoy script: https://github.com/spatie/blender/blob/master/Envoy.blade.php

Read more

Six reasons why JavaScript’s async/await blows promises away

Link –

In the JavaScript world promises are a great way to deal with stuff that needs to happen asynchronously. But there's also another new way to go about it: async/await.

In case you missed it, Node now supports async/await out of the box since version 7.6. If you haven’t tried it yet, here are a bunch of reasons with examples why you should adopt it immediately and never look back.

For those who have never heard of this topic before, here’s a quick intro

  • Async/await is a new way to write asynchronous code. Previous options for asynchronous code are callbacks and promises.
  • Async/await is actually built on top of promises. It cannot be used with plain callbacks or node callbacks.
  • Async/await is, like promises, non blocking.
  • Async/await makes asynchronous code look and behave a little more like synchronous code. This is where all its power lies.

https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9

Read more

Creating strictly typed arrays and collections in PHP

Link –

You might thing that PHP is not able to automatically perform a type check on items in an array. But using variadic constructor this is possible. Bert Ramakers wrote a blogpost with some good examples on how to do this.

One of the language features announced back in PHP 5.6 was the addition of the “…” token to denote that a function or method accepts a variable length of arguments.

Something I rarely see mentioned is that it’s possible to combine this feature with type hints to essentially create typed arrays.

https://medium.com/2dotstwice-connecting-the-dots/creating-strictly-typed-arrays-and-collections-in-php-37036718c921

Read more

Partial model updates in Laravel

Link –

Michael Dyrynda, one of the co-hosts of the Laravel News and the North Meets South podcasts, explains how to easily uptime your models with data coming from requests.

Instead of littering your controller method with multiple request()->has('field') checks, you can employ the request object's intersect method. The intersect method will return a new array containing only the keys that are present in both the specified list and the request itself.

Using intersect allows you to easily handle a PATCH request - one where you partially update a resource's data, rather than all of it as with a PUT - in a much more concise manner.

https://dyrynda.com.au/blog/partial-model-updates-in-laravel

Read more

Make git work better with GitHub

Original – by Freek Van der Herten – 1 minute read

A few months ago I installed a command line utility called hub. I'm really fond of it. It's aim is to make it easier to interact with GitHub from the commandline. It's a wrapper around the standard git command. Once it's installed you can do stuff like this (take from the manual page) # clone your…

Read more

Comparing Vue with other frameworks

Link –

Recently I stumbled upon a page in the VueJs docs where Vue is compared against all other similar frameworks. I'm impressed with the fact that they reached out to authors of the other frameworks to get well balanced comparison.

This is definitely the most difficult page in the guide to write, but we do feel it’s important. Odds are, you’ve had problems you tried to solve and you’ve used another library to solve them. You’re here because you want to know if Vue can solve your specific problems better. That’s what we hope to answer for you.

We also try very hard to avoid bias. As the core team, we obviously like Vue a lot. There are some problems we think it solves better than anything else out there. If we didn’t believe that, we wouldn’t be working on it. We do want to be fair and accurate though. Where other libraries offer significant advantages, such as React’s vast ecosystem of alternative renderers or Knockout’s browser support back to IE6, we try to list these as well.

https://vuejs.org/v2/guide/comparison.html

Read more

Stack Overflow's Developer Survey results

Link –

Every year Stack Overflow runs as survey where they asks their users about their favourite tools, languages, etc... A little while ago they published the results of the 2017 edition.

We learn something new every time we run our survey. This year is no exception:

- A common misconception about developers is that they've all been programming since childhood. In fact, we see a wide range of experience levels. Among professional developers, 11.3% got their first coding jobs within a year of first learning how to program. A further 36.9% learned to program between one and four years before beginning their careers as developers. - Only 13.1% of developers are actively looking for a job. But 75.2% of developers are interested in hearing about new job opportunities. - When we asked respondents what they valued most when considering a new job, 53.3% said remote options were a top priority. A majority of developers, 63.9%, reported working remotely at least one day a month, and 11.1% say they’re full-time remote or almost all the time. - A majority of developers said they were underpaid. Developers who work in government and non-profits feel the most underpaid, while those who work in finance feel the most overpaid.

https://stackoverflow.com/insights/survey/2017/

Read more

Sharing Data in a Laravel/Vue Application

Link –

There are multiple good ways to pass data from Laravel to Vue. In a new blogpost Jesse Schutt covers all the options.

It has been helpful to think of my application as "layers" or separate sections of code each with varying responsibilities. I like to think of Laravel as the intermediary between the persistent data in the database, and the Vue components comprising the front-end of the app.

Though the boundaries between Laravel and Vue may appear unclear at the outset, the only way one can know about the other's data is if it is explicitly passed. Blade templates implicitly know a lot about the application, but Vue operates on a different layer, so it only knows what we tell it. Fortunately, there are a number of ways to provide Vue with the data it needs.

https://zaengle.com/blog/layers-of-a-laravel-vue-application

Read more

A Laravel package to quickly dump and load the database

Original – by Freek Van der Herten – 1 minute read

Last week our team released a new package called laravel-db-snapshots. It provides a few artisan commands to quickly dump and load a database. We've built this for is to help us develop features in an app that require the database to be in a specific state. With this package we can take a dump of…

Read more

How we improved our PWA score by 53 points in 4 hours

Link –

On the madewithlove blog Frederick Vanbrabant wrote a post on how he and colleague improved the PWA score of their company site.

So the first thing you should know about PWA (or progressive web apps) is that it’s an adaptation of your current site or web app. This means that if you want to have all the features of a progressive web app, you are going to need to change your current site/application. The good news here is that they are all changes you would want to have anyway.

https://blog.madewithlove.be/post/improved_pwa_score

Read more

Visualizing PHPUnit Tests

Link –

In an article on the Hackster.io site explains in detail how he made a nice visualization of unit test results. Pretty cool what you can do with a raspberry pi, some LEDS and a couple of scripts.

I wanted to create a desktop gadget to visualize the progress of unit tests run via PHPUnit.I've named this project PHPUnicorn (by combining "PHPUnit" with "Unicorn pHAT").

https://www.hackster.io/colinodell/phpunicorn-visualizing-phpunit-tests-896208

Read more

Working With PHPUnit and PhpStorm

Link –

On the JetBrains blog Gary Hockin explains how to easily run a single PHPUnit test.

To run all the tests in a single file, right-click the test in the Project Pane (the left-hand navigation pane), and select Run .

To run all the tests in a single class, right-click the class name in the editor, and select Run .

To run the tests in a single method, right-click the method name, and select Run .

https://blog.jetbrains.com/phpstorm/2017/01/working-with-phpunit-and-phpstorm/

Read more

Understanding Laravel’s HighOrder Collections

Link –

One of my favourite features that was introduced in Laravel 5.4 are the higher order collection functions. It allows you to rewrite

collect($models)->filter(function(Model $model) {
   $model->passesFilter();
});

to:

collect($models)->filter->passesFilter();

This works with the filter method an a bunch of other collection methods.

In a new post on his blog Nicola Malizia explains how these methods work under the hood.

A new version of Laravel is available from 24 January 2017 and, as usual, it comes with a lot of new features. Among them, there is one that takes advantage of the dynamic nature of PHP. Some out of there will contempt this, but I find it awesome!

https://unnikked.ga/understanding-laravels-highorder-collections-ee4f65a3029e

Read more

Closure Binding as an alternative to “use” variables

Link –

On his blog Mark Baker shares some thoughts on how to use closure binding to avoid having import variables with the use keyword.

You'll learn how to rewrite

$filteredArrayData = array_filter(
    $arrayData,
    function($value) use ($minimumPrice, $maximumPrice) {
        return $value->price >= $minimumPrice &amp;&amp; $value->price < $maximumPrice;
    }
);

to

$filteredArrayData = array_filter(
    $bookData,
    $priceFilter->inRange(5.00, 15.00)
);

https://markbakeruk.net/2017/03/12/closure-binding-as-an-alternative-to-use-variables/

Read more

10 Lodash Features You Can Replace with ES6

Link –

In the JavaScript world Lodash is a pretty popular and awesome package with lots of handy array, collection and object methods. In this article Dan Prince explains that some of those methods do have a nice ES6 equivalent.

Lodash is the most depended on npm package right now, but if you’re using ES6, you might not actually need it. In this article, we’re going to look at using native collection methods with arrow functions and other new ES6 features to help us cut corners around many popular use cases.

https://www.sitepoint.com/lodash-features-replace-es6/

Read more