How to refactor complex if statements

Original – by Freek Van der Herten – 1 minute read

Have you every come across confusing if statements with complex conditionals such as this? I bet you did!

// please kill me 🀯 
if (!(($this->shipping_country == "GB" ||Β (strcmp($this-status, "Valid") !== 0)) {

To me, this is completely unreadable.

In the video below I show how I deal with this situation. Spoiler: add some tests around it and break the conditionals apart.

This video is part of the Mailcoach video course. It contains many more videos on how to write clear code. You can use this coupon code to get a nice discount of $10.

YES-I-WANT-TO-WRITE-READABLE-CODE

Read more

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

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks 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.

Laravel Tail can now tail remote logs

Original – by Freek Van der Herten – 2 minute read

laravel-tail is one of my favourite packages. When installed in a Laravel app it can be used to tail the log file. To tail a log file locally, you just have to issue this command: php artisan tail and it'll start tailing the latest log file (so it works for both daily and single log files). Any line…

Read more

Pragmatically testing multi-guard authentication in Laravel

Original – by Freek Van der Herten – 2 minute read

Last week our team launched Mailcoach, a self-hosted solution to send out email campaigns and newsletters. Rather than being the end, laughing something is the beginning of a journey. Users start encountering bugs and ask for features that weren't considered before.

One of those features requests we got, is the ability the set the guard to be used when checking if somebody is allowed to access the Mailcoach UI.

In this blog post, I'd like to show you how we implemented and tested this.

Read more

Building Mailcoach

Original – by Freek Van der Herten – 12 minute read

Today, our team released Mailcoach, a beautiful, self-hosted mailing list manager. It integrates with services like Amazon SES, Mailgun, or Sendgrid to send out mailings affordably. It’s packaged as a stand-alone app, or can be integrated into a Laravel project, it's perfect for bloggers, artisans, and entrepreneurs.

Even if you're not in the market for an email solution, Mailcoach includes a video course on how it’s built. I'm sure you'll see some valuable techniques that you can bring to your own project.

In this blogpost, I'd like to share why and how we've built this.

Read more

Remove all history from a GitHub repository

Original – by Freek Van der Herten – 2 minute read

From time to time I need to remove all history from a GitHub repository, for instance right before releasing a package I've worked on in private. Sometimes I don't want people to see all mistakes I've made along the way :-).

Read more

Streaming a large export as a CSV file to the browser

Original – by Freek Van der Herten – 3 minute read

A while ago, I created an easy to use framework agnostic PHP package to read and write CSV and Excel files called spatie/simple-excel. Behind the scenes, generators are used to ensure low memory usage, even when working with large files. Today I added a method that allows you to stream CSV files to the browser. In this small blog post, I'd like to demonstrate how you can use it.

Read more