πŸ”₯ Weekly thread #50 of 2021

πŸ”₯ This week's code tips for Laravel developers

A weekly thread 🧡

You can add a --refresh flag to the artisan down command to send a refresh header to the browser

6

πŸ”₯ You can add a --refresh flag to the artisan down command to send a refresh header to the browser

You can add a --refresh flag to the artisan down command to send a refresh header to the browser

#WeirdDevReadsDocs

Did you know?

You can add a --refresh flag to the artisan down command to send a refresh header to the browser. I think that's helpful for well visited apps where you trying to keep perceived downtime as low as possible!

https://laravel.com/docs/8.x/configuration#maintenance-mode

@laravelphp

Use match () or switch () statements to conditionally scope database queries based on query strings in the request

4

πŸ”₯ Use match () or switch () statements to conditionally scope database queries based on query strings in the request

Use match () or switch () statements to conditionally scope database queries based on query strings in the request

Remembered this great tip recently, and it's nice to see how fast PHP evolves

The exact same behavior can be implemented using match () with a default value, which also removes the need for the second callback ⚑️ https://twitter.com/reinink/status/1233017064492761088

Adding WHERE scopes which use an indexed column to a query that's primarily filtered by another column is a great way to speed up DB performance

3

πŸ”₯ Adding WHERE scopes which use an indexed column to a query that's primarily filtered by another column is a great way to speed up DB performance

Adding WHERE scopes which use an indexed column to a query that's primarily filtered by another column is a great way to speed up DB performance

⚑️ Database Tip

Sometimes you have seldom used queries and you can't add an index on columns for these queries. A nice trick is to use another indexed condition so the rows are filtered by the indexable column first and afterwards again for the more limiting condition.

You can use the array spread syntax to pass an array of arguments to another function

2

πŸ”₯ You can use the array spread syntax to pass an array of arguments to another function

You can use the array spread syntax to pass an array of arguments to another function

πŸ”₯ You can use array spreading to pass an array as arguments to another function. #php

Here’s a self-contained example where we spread the array output of sys_getloadavg. That function returns an array with three elements.

https://github.com/spatie/cpu-load-health-check/blob/70f387d5167c24d4000d825a5bddab2504d557fb/src/CpuLoad.php#L17

#php

Use retry() for callbacks that may randomly fail

1

πŸ”₯ Use retry() for callbacks that may randomly fail

Use retry() for callbacks that may randomly fail

.@laravelphp out here helping me again, with its helpers!

I was hitting a shaky API that sometimes failed.

Here, the retry function tries the callback 3 times, with a 2 second interval in-between retries.

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