Reading List

The most recent articles from a list of feeds I subscribe to.

Remove falsy values from a Laravel collection or array in PHP

The native array_filter() in PHP and collect()->filter() in Laravel also work without providing a filter callback.

array_filter([0, 1, '', 'a', false, true, []]);
// [1, 'a', true]
 
collect([0, 1, '', 'a', false, true, []])->filter();
// [1, 'a', true]

If you don't provide a callback, PHP will remove all empty values from the array.

Cosmic Latte

A team of astronomers have calculated the average color of the universe and named it cosmic latte. I'd love to have a cosmiclatte CSS color one day.

en.wikipedia.org

Adding stale while revalidate functionality to Laravel's cache

A stale while revalidate cache macro by Rias Van der Veken. With stale while revalidate, expired cache items will still be used when requested, but the data will be revalidated right after. That means the current request will be handled faster than if the cache would have to be revalidated, and the next request will receive fresh data.

Stale while revalidate is often used in web applications, popularized by Vercel's SWR React library.

rias.be

Technology didn’t have to glow

Technology didn’t have to glow. […] There were devices that simply did what they were for, without demanding attention.

I've always had a soft-spot for e-ink screens. Tom MacWright puts it better than I ever could, we should be the ones demanding attention from technology, not vice-versa.

macwright.com

Stefan Zweifel on storing user preferences in a Laravel application

Stefan Zweifel explains how he stores user preferences in a Laravel application using spatie/laravel-data. With the data package, you can store user settings as a blog of JSON in your database—so you don't need to update your table schema for every change—and have a typed object to work with in code.

He mentions poor query performance as a possible tradeoff if you need to query the database for a specific value.

One thing to keep in mind is that querying for specific settings can lead to performance issues and should probably be avoided.

If your app regularly needs to query for users who have selected a particular date_format , it's better to promote this setting to its own column. This makes the work of your database and possible indexing much easier.

If this is something you need, you could solve it with a virtual column mapped to a JSON value of the settings object. There's a nice tutorial on that on the Kirschbaum blog

stefanzweifel.dev