1
0
Fork 0
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:
Samuel Štancl 2022-05-22 13:50:08 +02:00
parent 23979938b4
commit 99fc7428d1
5 changed files with 61 additions and 0 deletions

View file

@ -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 💅

View file

@ -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. Heres an example where I sort roles based on their level of importance (rather than their alphabetical order).

View file

@ -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!

View 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! 👌