๐Ÿ”ฅ Weekly thread #47 of 2021

๐Ÿ”ฅ This week's code tips for Laravel developers

A weekly thread ๐Ÿงต

Use aggregate methods to count related models

6

๐Ÿ”ฅ Use aggregate methods to count related models

Use aggregate methods to count related models

When you're counting related models in @laravelphp, opt for aggregates!

๐Ÿ‘Ž Using the count() method on a collection of related models is a tad slower.

You can implement the ShouldBeEncrypted interface on your jobs to encrypt their payload before they get pushed to the queue

4

๐Ÿ”ฅ You can implement the ShouldBeEncrypted interface on your jobs to encrypt their payload before they get pushed to the queue

You can implement the ShouldBeEncrypted interface on your jobs to encrypt their payload before they get pushed to the queue

๐Ÿ’ก Since @laravelphp v8.19, there is a ShouldBeEncrypted interface that jobs can implement. This encrypts the payload, for example, in case the properties hold sensitive data.

As of v8.25, this works for Listeners, Mailables, and Notifications as well ๐Ÿ’ซ

#Laravel #PHP #webdev https://twitter.com/pascalbaljet/status/1462711618329055232

You can convert Eloquent Collections back to a Query Builder instance

3

๐Ÿ”ฅ You can convert Eloquent Collections back to a Query Builder instance

You can convert Eloquent Collections back to a Query Builder instance

A tiny tip about #laravel eloquent.

To retrieve the Query Builder after filtering the results: you can use ->toQuery().

The method internally use the first model of the collection and a whereKey comparison on the Collection models.

Use prefetching to boost the perceived speed of Livewire apps

1

๐Ÿ”ฅ Use prefetching to boost the perceived speed of Livewire apps

Use prefetching to boost the perceived speed of Livewire apps

To boost perceived speed in your @LaravelLivewire apps when loading data, make use of prefetching.

The .prefetch modifier tells Livewire to fetch the result in the background on hover, and then displays the result when the button is actually clicked โœจ

We're writing a book, you can get it for free here.