mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 05:14:04 +00:00
Weekly thread #50
This commit is contained in:
parent
59205f1326
commit
e44c3d0f65
8 changed files with 107 additions and 0 deletions
5
content/authors/DianaWebdev.md
Normal file
5
content/authors/DianaWebdev.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
username: DianaWebdev
|
||||||
|
name: Di
|
||||||
|
avatar: 'https://pbs.twimg.com/profile_images/1437883999955869707/9Pz4IAhZ_normal.jpg'
|
||||||
|
---
|
||||||
11
content/threads/weekly-thread-2021-01.md
Normal file
11
content/threads/weekly-thread-2021-01.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
slug: weekly-thread-2021-01
|
||||||
|
title: 'Weekly thread #01 of 2021'
|
||||||
|
tweet_id: '1471864631312404492'
|
||||||
|
author_username: archtechx
|
||||||
|
created_at: 2022-01-07T12:56:47+00:00
|
||||||
|
links: { }
|
||||||
|
---
|
||||||
|
🔥 This week's code tips for Laravel developers
|
||||||
|
|
||||||
|
A weekly thread 🧵
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
title: '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'
|
||||||
|
tweet_id: '1471864653491974151'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: tobias_petry
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FGafd_JXMAEDgP5.jpg'
|
||||||
|
created_at: 2021-12-17T15:27:33+00:00
|
||||||
|
slug: adding-where-scopes-which-use-an-indexed-column-to-a-query-thats-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.
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
title: 'Use match () or switch () statements to conditionally scope database queries based on query strings in the request'
|
||||||
|
tweet_id: '1471864655710670854'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: archtechx
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FGmQH5nXEAs4mnv.jpg'
|
||||||
|
created_at: 2021-12-17T15:27:34+00:00
|
||||||
|
slug: 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
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
title: 'Use retry() for callbacks that may randomly fail'
|
||||||
|
tweet_id: '1471864638199451648'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: alexjgarrett
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FGP3MSQWQAYKjSm.jpg'
|
||||||
|
created_at: 2021-12-17T15:27:30+00:00
|
||||||
|
slug: 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.
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
title: 'You can add a --refresh flag to the artisan down command to send a refresh header to the browser'
|
||||||
|
tweet_id: '1471864676652826626'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: DianaWebdev
|
||||||
|
images: { }
|
||||||
|
created_at: 2021-12-17T15:27:39+00:00
|
||||||
|
slug: 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
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
title: 'You can refactor cluttered if () conditions using lookup tables, match statements, and switch statements'
|
||||||
|
tweet_id: '1471864664661311488'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: archtechx
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FGVrAKdVgAIWfwk.jpg'
|
||||||
|
created_at: 2021-12-17T15:27:36+00:00
|
||||||
|
slug: you-can-refactor-cluttered-if-conditions-using-lookup-tables-match-statements-and-switch-statements
|
||||||
|
---
|
||||||
|
🔥 Three ways you can refactor cluttered if () conditions
|
||||||
|
|
||||||
|
First: lookup tables 👇
|
||||||
|
|
||||||
|
These are great for refactoring complex conditions with lots of else if () cases
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
title: 'You can use the array spread syntax to pass an array of arguments to another function'
|
||||||
|
tweet_id: '1471864644562305025'
|
||||||
|
thread_slug: weekly-thread-2021-01
|
||||||
|
author_username: freekmurze
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FGepj8mWQAUf2R_.jpg'
|
||||||
|
created_at: 2021-12-17T15:27:31+00:00
|
||||||
|
slug: 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue