From 99fc7428d1af93218fda2bc7318bda2f8c5238ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 22 May 2022 13:50:08 +0200 Subject: [PATCH] Week 20/2022 --- content/threads/weekly-thread-2022-20.md | 11 +++++++++++ ...nsider-creating-helpers-for-model-factories.md | 15 +++++++++++++++ ...very-useful-for-complex-sorting-in-eloquent.md | 11 +++++++++++ ...forcing-rules-that-only-apply-conditionally.md | 13 +++++++++++++ .../tips/you-can-unpack-arrays-in-conditions.md | 11 +++++++++++ 5 files changed, 61 insertions(+) create mode 100644 content/threads/weekly-thread-2022-20.md create mode 100644 content/tips/consider-creating-helpers-for-model-factories.md create mode 100644 content/tips/orderbyraw-is-very-useful-for-complex-sorting-in-eloquent.md create mode 100644 content/tips/partial-indexes-are-useful-for-enforcing-rules-that-only-apply-conditionally.md create mode 100644 content/tips/you-can-unpack-arrays-in-conditions.md diff --git a/content/threads/weekly-thread-2022-20.md b/content/threads/weekly-thread-2022-20.md new file mode 100644 index 0000000..c3af880 --- /dev/null +++ b/content/threads/weekly-thread-2022-20.md @@ -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 🧵 \ No newline at end of file diff --git a/content/tips/consider-creating-helpers-for-model-factories.md b/content/tips/consider-creating-helpers-for-model-factories.md new file mode 100644 index 0000000..5f1400d --- /dev/null +++ b/content/tips/consider-creating-helpers-for-model-factories.md @@ -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 💅 \ No newline at end of file diff --git a/content/tips/orderbyraw-is-very-useful-for-complex-sorting-in-eloquent.md b/content/tips/orderbyraw-is-very-useful-for-complex-sorting-in-eloquent.md new file mode 100644 index 0000000..1663f64 --- /dev/null +++ b/content/tips/orderbyraw-is-very-useful-for-complex-sorting-in-eloquent.md @@ -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). \ No newline at end of file diff --git a/content/tips/partial-indexes-are-useful-for-enforcing-rules-that-only-apply-conditionally.md b/content/tips/partial-indexes-are-useful-for-enforcing-rules-that-only-apply-conditionally.md new file mode 100644 index 0000000..011c878 --- /dev/null +++ b/content/tips/partial-indexes-are-useful-for-enforcing-rules-that-only-apply-conditionally.md @@ -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! \ No newline at end of file diff --git a/content/tips/you-can-unpack-arrays-in-conditions.md b/content/tips/you-can-unpack-arrays-in-conditions.md new file mode 100644 index 0000000..7cf7e26 --- /dev/null +++ b/content/tips/you-can-unpack-arrays-in-conditions.md @@ -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! 👌 \ No newline at end of file