In this section you can read posts I've written myself.

Increase performance by using Eloquent's `setRelation` method

Original – by Freek Van der Herten – 5 minute read

While working on the upcoming Oh Dear redesign, I noticed that list that displays all sites of a team was very slow.

To display that list, a lot of queries were used. With a couple of minor adjustments, I could reduce the number of queries needed to just a single one, solving the performance problem.

In this small blog post, I'd like to share one of the techniques I used.

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 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.

Introducing our new Laravel Options package

Original – by Ruben Van Assche – 2 minute read

When developing web applications, you probably encounter a lot of places where someone needs to select one or more options in a select or multi-select. These select boxes always need a list of options with labels and values.

In one of our projects, we had options being generated in lots of places. Sometimes these lists of options were the same, leading to a lot of code duplication. Even worse, in some cases, different formats were used to output the same options.

That's why we've created a new package called spatie/laravel-options. It will take a resource which can create options such as an enum, a list of models or even a plain array. And will always create a standardized array of options you can use within your frontend application.

Read more

Using Laravel Vite to automatically refresh your browser when changing a Blade file

Original – by Freek Van der Herten – 2 minute read

Yesterday, the Laravel team released the vite-plugin. Going forward, Vite will become the standard build tool for Laravel apps.

One of the cool features of this Vite integration is that you'll get hot reloading by default. Whenever you run Vite with npm dev and modify a JS or CSS file, Vite will automatically recompile the assets and refresh your browser. This way, you won't have to refresh your browser manually after making a change.

Wouldn't it be cool if this automatic refresh would work when we're changing a Blade file?

Read more

Making Vite and Valet play nice together

Original – by Freek Van der Herten – 3 minute read

Yesterday, the Laravel team launched the official vite-plugin. From now on, Vite will be the standard build tool for Laravel. The main benefits are vastly improved build times and a more straightforward API. Want to know more about it? Head over to the official docs. There's also a migration guide to go from Mix to Vite.

When I followed that guide to upgrade the freek.dev codebase from Mix to Vite , npm dev could successfully start-up Vite, but in the browser the JS / CSS did not load. Let's review how I could fix that.

Read more

Using the `Attachable` interface to attach any kind of object to a mail in a Laravel app

Original – by Freek Van der Herten – 4 minute read

Laravel 9 has gained a excellent new way to attach files in mails. Using the Attachable interface, you can specify what should happen when an object gets used as an attachment.

Using our media library package you can easily associate any file with an Eloquent model. We've added support for Laravel's Attachable in the latest version of the package.

In this blog post, I'd like to tell you all about it.

Read more

A package to add comments to your Laravel app

Original – by Freek Van der Herten – 10 minute read

I'm proud to announce that our team has released a new premium package called Laravel Comments. Using this package, you can set up a comments section in your Laravel app in no time.

We've made a nice, errr I mean epic launch movie to get you in the right mood.

Laravel Comments includes a Livewire component to render comments. Here's what it looks like:

screenshot

Of course, we wrote extensive documentation, covering every aspect of Laravel Comments.

It comes with batteries included:

  • comments can be nested
  • emoji reactions
  • notifications to all participants when a new comment is posted
  • an inline approval flow for new comments
  • markdown editing and code highlighting
  • endlessly customisable

In this blog post, I'd like to introduce the package to you.

Read more

A package to create Livewire powered wizards in no time

Original – by Freek Van der Herten – 9 minute read

I'm proud to announce that our team has released a new package called laravel-livewire-wizard. Using this package, you can set up multi-step wizards quickly using Livewire.

The package is headless, which means that it provides no UI itself, but it makes it easy to build any UI you desire.

You can easily control which step is displayed, access state of other steps, and build any navigation you desire.

I'd like to introduce the package to you in this blog post.

Read more

How to add a spotlight-like search field to your Laravel app

Original – by Freek Van der Herten – 6 minute read

As developers, we tend to like shortcuts to speed up our workflow. One of the tools I'm using to speed up doing stuff on my Mac is Raycast. It offers a lovely command palette that allows opening apps and URLs, working with clipboard history, and much more.

Wouldn't it be nice to also add such a command palette to a Laravel app? This way, power users of your app can get around quickly and perform small tasks without having to click around.

The good news is that there's already a package to add such a thing: Spotlight by Philo Hermans. In this blog post, I'd like to show how we use this fantastic package at Oh Dear.

Read more

Learn how to write readable PHP that is a joy to maintain

Original – by Freek Van der Herten – 8 minute read

I'm proud to announce that our new premium course on writing readable PHP is now available. It's called Writing Readable PHP.

This course contains a collection of bite-size tips (both in written form and videos) that make your code a joy to read for your co-workers and future self. These tips are aimed towards developers who know the basics of PHP and want to improve their craft. As a bonus, you'll learn to use static analysis to ensure that your code is understandable and correct.

Writing Readable PHP has been created by our team and Christoph Rumpel. It contains our combined knowledge on how to write the best PHP possible.

Read more

Avoid using else

Original – by Freek Van der Herten – 1 minute read

Using else often encourages complexer code structure, makes code less readable. In most cases you can refactor it using early returns.

Read more

Code that breathes

Original – by Brent Roose & Freek Van der Herten – 2 minute read

Have you ever needed to maintain a project that wasn't yours? A project that, when you first opened it, gave you chills down your spine? Even without reading the code in detail, you could already tell it was a mess.

Read more

A package to automatically discover routes in a Laravel app

Original – by Freek Van der Herten – 9 minute read

I'm proud to announce that our team has released a new package called spatie/laravel-route-discovery. This package can be used to automatically discover and register routes by looking at your controllers and views. Of course, you can also still register routes like you're used to in a routes file.

In this blog post, I'd like to tell you all about this package.

Read more