mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 05:14:04 +00:00
Week 20/2022
This commit is contained in:
parent
23979938b4
commit
99fc7428d1
5 changed files with 61 additions and 0 deletions
11
content/threads/weekly-thread-2022-20.md
Normal file
11
content/threads/weekly-thread-2022-20.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
slug: weekly-thread-2022-20
|
||||||
|
title: 'Weekly thread #20 of 2022'
|
||||||
|
tweet_id: '1527688608286535680'
|
||||||
|
author_username: archtechx
|
||||||
|
created_at: 2022-05-20T16:32:01+00:00
|
||||||
|
links: { }
|
||||||
|
---
|
||||||
|
🔥 This week's code tips for Laravel developers
|
||||||
|
|
||||||
|
A weekly thread 🧵
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
title: 'Consider creating helpers for model factories'
|
||||||
|
tweet_id: '1527688619753779200'
|
||||||
|
thread_slug: weekly-thread-2022-20
|
||||||
|
author_username: archtechx
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FTL7hJEVIAAkVsa.jpg'
|
||||||
|
created_at: 2022-05-20T16:32:04+00:00
|
||||||
|
slug: consider-creating-helpers-for-model-factories
|
||||||
|
---
|
||||||
|
If your app has only a few models, consider creating helper functions for model factories
|
||||||
|
|
||||||
|
Helpers have perfect IDE support and can make your tests a lot cleaner
|
||||||
|
|
||||||
|
Pairs especially well with @pestphp 💅
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
title: 'orderByRaw() is very useful for complex sorting in Eloquent'
|
||||||
|
tweet_id: '1527688616838803456'
|
||||||
|
thread_slug: weekly-thread-2022-20
|
||||||
|
author_username: mattkingshott
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FS-AaRbWAAA5Xfl.jpg'
|
||||||
|
created_at: 2022-05-20T16:32:03+00:00
|
||||||
|
slug: orderbyraw-is-very-useful-for-complex-sorting-in-eloquent
|
||||||
|
---
|
||||||
|
🔥 #Laravel Tip: Make use of ‘orderByRaw’ when you need to sort records in a more complex manner than simply A-Z or Z-A. Here’s an example where I sort ‘roles’ based on their level of importance (rather than their alphabetical order).
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
title: 'Partial indexes are useful for enforcing rules that only apply conditionally'
|
||||||
|
tweet_id: '1527688613932044289'
|
||||||
|
thread_slug: weekly-thread-2022-20
|
||||||
|
author_username: tobias_petry
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FTCG2anXoAIB0U2.jpg'
|
||||||
|
created_at: 2022-05-20T16:32:03+00:00
|
||||||
|
slug: partial-indexes-are-useful-for-enforcing-rules-that-only-apply-conditionally
|
||||||
|
---
|
||||||
|
⚡️ Database Tip
|
||||||
|
|
||||||
|
Sometimes you want to make columns unique but you can't because e.g. there are still soft-deleted rows in the table witht the same value. By only including relevant rows (partial index) you can still enforce uniqueness, and you can even simulate it for MySQL!
|
||||||
11
content/tips/you-can-unpack-arrays-in-conditions.md
Normal file
11
content/tips/you-can-unpack-arrays-in-conditions.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
title: 'You can unpack arrays in conditions'
|
||||||
|
tweet_id: '1527688611008679936'
|
||||||
|
thread_slug: weekly-thread-2022-20
|
||||||
|
author_username: SteveTheBauman
|
||||||
|
images:
|
||||||
|
- 'https://pbs.twimg.com/media/FSvAVOOWIAIMa5Y.jpg'
|
||||||
|
created_at: 2022-05-20T16:32:02+00:00
|
||||||
|
slug: you-can-unpack-arrays-in-conditions
|
||||||
|
---
|
||||||
|
Today I learned you can unpack conditionally in PHP, pretty neat! 👌
|
||||||
Loading…
Add table
Add a link
Reference in a new issue